diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 58e5564b..a93c4a95 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -105,24 +105,19 @@ class SubmissionsController < ApplicationController # are registered first, the runner socket may still be nil. client_socket, runner_socket = nil - @tubesock_debug_events = [] - client_kill = false hijack do |tubesock| client_socket = tubesock - client_socket.onopen do |event| - @tubesock_debug_events << {type: :open, data: event} + client_socket.onopen do |_event| kill_client_socket(client_socket) and return true if @embed_options[:disable_run] end - client_socket.onclose do |event| - @tubesock_debug_events << {type: :close, data: event} + client_socket.onclose do |_event| runner_socket&.close(:terminated_by_client) @testrun[:status] ||= :terminated_by_client end client_socket.onmessage do |raw_event| - @tubesock_debug_events << {type: :message, data: raw_event} # Obviously, this is just flushing the current connection: Filtering. next if raw_event == "\n" @@ -138,7 +133,6 @@ class SubmissionsController < ApplicationController case event[:cmd] when :client_kill - client_kill = true @testrun[:status] = :terminated_by_client close_client_connection(client_socket) Rails.logger.debug('Client exited container.') @@ -163,10 +157,6 @@ class SubmissionsController < ApplicationController Sentry.set_extras(data: raw_event) Sentry.capture_exception(e) end - - client_socket.onerror do |event| - @tubesock_debug_events << {type: :error, data: event} - end end # If running is not allowed (and the socket is closed), we can stop here. @@ -176,7 +166,6 @@ class SubmissionsController < ApplicationController durations = @submission.run(@file) do |socket, starting_time| runner_socket = socket @testrun[:starting_time] = starting_time - @tubesock_debug_events << {type: :send, data: {cmd: :status, status: :container_running}} client_socket.send_data JSON.dump({cmd: :status, status: :container_running}) runner_socket.on :stdout do |data| @@ -248,13 +237,11 @@ class SubmissionsController < ApplicationController Sentry.capture_exception(e) extract_durations(e) ensure - close_client_connection(client_socket) unless client_kill + close_client_connection(client_socket) save_testrun_output 'run' - Sentry.capture_message('Execution got terminated by client', extra: {websocket: @tubesock_debug_events, submission: @submission.id}) if @testrun[:status] == :terminated_by_client && !client_kill end def score - @tubesock_debug_events = [] client_socket = nil disable_scoring = @embed_options[:disable_score] || !@submission.exercise.teacher_defined_assessment? @@ -300,7 +287,6 @@ class SubmissionsController < ApplicationController def statistics; end def test - @tubesock_debug_events = [] client_socket = nil hijack do |tubesock| @@ -354,7 +340,6 @@ class SubmissionsController < ApplicationController # We don't want to store this (arbitrary) exit command and redirect it ourselves client_socket.send_data JSON.dump({cmd: :exit}) client_socket.send_data nil, :close - @tubesock_debug_events << {type: :send, data: {cmd: :exit}} # We must not close the socket manually (with `client_socket.close`), as this would close it twice. # When the socket is closed twice, nginx registers a `Connection reset by peer` error. # Tubesock automatically closes the socket when the `hijack` block ends and otherwise ignores `Errno::ECONNRESET`. @@ -416,7 +401,6 @@ class SubmissionsController < ApplicationController end @testrun[:messages].push message @testrun[:status] = message[:status] if message[:status] - @tubesock_debug_events << {type: :send, data: message} client_socket.send_data JSON.dump(message) end