@@ -52,15 +52,15 @@ public boolean hasSession(String id) {
5252
5353 public JShellService session (String id , @ Nullable StartupScriptId startupScriptId ) throws DockerException {
5454 if (!hasSession (id )) {
55- return createSession (id , config .regularSessionTimeoutSeconds (), true , config .evalTimeoutSeconds (), config .sysOutCharLimit (), startupScriptId );
55+ return createSession (id , config .regularSessionTimeoutSeconds (), true , config .evalTimeoutSeconds (), config .evalTimeoutValidationLeeway (), config . sysOutCharLimit (), startupScriptId );
5656 }
5757 return jshellSessions .get (id );
5858 }
5959 public JShellService session (@ Nullable StartupScriptId startupScriptId ) throws DockerException {
60- return createSession (UUID .randomUUID ().toString (), config .regularSessionTimeoutSeconds (), false , config .evalTimeoutSeconds (), config .sysOutCharLimit (), startupScriptId );
60+ return createSession (UUID .randomUUID ().toString (), config .regularSessionTimeoutSeconds (), false , config .evalTimeoutSeconds (), config .evalTimeoutValidationLeeway (), config . sysOutCharLimit (), startupScriptId );
6161 }
6262 public JShellService oneTimeSession (@ Nullable StartupScriptId startupScriptId ) throws DockerException {
63- return createSession (UUID .randomUUID ().toString (), config .oneTimeSessionTimeoutSeconds (), false , config .evalTimeoutSeconds (), config .sysOutCharLimit (), startupScriptId );
63+ return createSession (UUID .randomUUID ().toString (), config .oneTimeSessionTimeoutSeconds (), false , config .evalTimeoutSeconds (), config .evalTimeoutValidationLeeway (), config . sysOutCharLimit (), startupScriptId );
6464 }
6565
6666 public void deleteSession (String id ) throws DockerException {
@@ -69,7 +69,7 @@ public void deleteSession(String id) throws DockerException {
6969 scheduler .schedule (service ::close , 500 , TimeUnit .MILLISECONDS );
7070 }
7171
72- private synchronized JShellService createSession (String id , long sessionTimeout , boolean renewable , long evalTimeout , int sysOutCharLimit , @ Nullable StartupScriptId startupScriptId ) throws DockerException {
72+ private synchronized JShellService createSession (String id , long sessionTimeout , boolean renewable , long evalTimeout , long evalTimeoutValidationLeeway , int sysOutCharLimit , @ Nullable StartupScriptId startupScriptId ) throws DockerException {
7373 if (hasSession (id )) { //Just in case race condition happens just before createSession
7474 return jshellSessions .get (id );
7575 }
@@ -83,6 +83,7 @@ private synchronized JShellService createSession(String id, long sessionTimeout,
8383 sessionTimeout ,
8484 renewable ,
8585 evalTimeout ,
86+ evalTimeoutValidationLeeway ,
8687 sysOutCharLimit ,
8788 config .dockerMaxRamMegaBytes (),
8889 config .dockerCPUsUsage (),
@@ -91,6 +92,23 @@ private synchronized JShellService createSession(String id, long sessionTimeout,
9192 return service ;
9293 }
9394
95+ /**
96+ * Schedule the validation of the session timeout.
97+ * In case the code runs for too long, checks if the wrapper correctly followed the eval timeout and canceled it,
98+ * if it didn't, forcefully close the session.
99+ * @param id the id of the session
100+ * @param timeSeconds the time to schedule
101+ */
102+ public void scheduleEvalTimeoutValidation (String id , long timeSeconds ) {
103+ scheduler .schedule (() -> {
104+ JShellService service = jshellSessions .get (id );
105+ if (service == null ) return ;
106+ if (service .isInvalidEvalTimeout ()) {
107+ service .close ();
108+ }
109+ }, timeSeconds , TimeUnit .SECONDS );
110+ }
111+
94112 @ Autowired
95113 public void setConfig (Config config ) {
96114 this .config = config ;
0 commit comments