Skip to content

Commit e3471cb

Browse files
MrSerthDome-GER
authored andcommitted
Immediately close a WebSocket connection to a runner
The previous code mostly worked but there could be cases where stopping was delayed. This is especially problematic with the reservation of runners, since they could still be reserved (internally) without a visual indicator for the learners. The change in the SubmissionsController is optional, since a browser should also close the connection once `close_client_connection` is executed. However, this change might stop the runner earlier, which is especially useful in case of infinite loops.
1 parent 57a8058 commit e3471cb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/controllers/submissions_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def run # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplex
140140
case event[:cmd]
141141
when :client_kill
142142
@testrun[:status] = :terminated_by_client
143+
runner_socket&.close(:terminated_by_client)
143144
close_client_connection(client_socket)
144145
Rails.logger.debug('Client exited container.')
145146
when :result, :canvasevent, :exception

lib/runner/connection.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ def close(status)
8484
return unless active?
8585

8686
@status = status
87-
@socket.close
87+
# Close the WebSocket connection _immediately_
88+
# by scheduling it for the next execution of the EventMachine reactor run.
89+
# Otherwise, the message might be queued causing delays for users.
90+
EventMachine.next_tick do
91+
@socket.close
92+
end
8893
end
8994

9095
# Check if the WebSocket connection is currently established

0 commit comments

Comments
 (0)