ArnavBalyan commented on code in PR #495:
URL: https://github.com/apache/incubator-livy/pull/495#discussion_r2610169581


##########
repl/src/main/scala/org/apache/livy/repl/Session.scala:
##########
@@ -161,18 +163,25 @@ class Session(
     _statements.synchronized { _statements(statementId) = statement }
 
     Future {
-      setJobGroup(tpe, statementId)
-      statement.compareAndTransit(StatementState.Waiting, 
StatementState.Running)
+      val currentThread = Thread.currentThread()
+      statementThreads.put(statementId, currentThread)
+      try {
+        setJobGroup(tpe, statementId)
+        statement.compareAndTransit(StatementState.Waiting, 
StatementState.Running)
 
-      if (statement.state.get() == StatementState.Running) {
-        statement.started = System.currentTimeMillis()
-        statement.output = executeCode(interpreter(tpe), statementId, code)
-      }
+        if (statement.state.get() == StatementState.Running) {
+          statement.started = System.currentTimeMillis()
+          statement.output = executeCode(interpreter(tpe), statementId, code)
+        }
 
-      statement.compareAndTransit(StatementState.Running, 
StatementState.Available)
-      statement.compareAndTransit(StatementState.Cancelling, 
StatementState.Cancelled)
-      statement.updateProgress(1.0)
-      statement.completed = System.currentTimeMillis()
+        statement.compareAndTransit(StatementState.Running, 
StatementState.Available)
+        statement.compareAndTransit(StatementState.Cancelling, 
StatementState.Cancelled)
+        statement.updateProgress(1.0)
+        statement.completed = System.currentTimeMillis()
+      } finally {
+        statementThreads.remove(statementId, currentThread)

Review Comment:
   This is actually safer, we only remove the thread for the statement id we 
are aware of. For any case where the thread has updated for the same statement 
id, the code does not touch that thread



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to