From 3240ea7076f18f756ec6f622ae951852fe65115b Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 11 Oct 2021 09:44:34 +0200 Subject: [PATCH] Forward input as raw_event to runner * Also, rename #send to #send_data in order to prevent debugging issues in RubyMine --- app/controllers/submissions_controller.rb | 10 ++++++---- lib/runner/connection.rb | 2 +- lib/runner/strategy/docker_container_pool.rb | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 551775e6..55f04458 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -95,21 +95,23 @@ class SubmissionsController < ApplicationController runner_socket&.close(:terminated_by_client) end - client_socket.onmessage do |event| - event = JSON.parse(event).deep_symbolize_keys + client_socket.onmessage do |raw_event| + event = JSON.parse(raw_event).deep_symbolize_keys case event[:cmd].to_sym when :client_kill close_client_connection(client_socket) Rails.logger.debug('Client exited container.') - when :result + when :result, :canvasevent, :exception # The client cannot send something before the runner connection is established. if runner_socket.present? - runner_socket.send event[:data] + runner_socket.send_data raw_event else Rails.logger.info("Could not forward data from client because runner connection was not established yet: #{event[:data].inspect}") end else Rails.logger.info("Unknown command from client: #{event[:cmd]}") + Sentry.set_extras(event: event) + Sentry.capture_message("Unknown command from client: #{event[:cmd]}") end rescue JSON::ParserError => e Rails.logger.info("Data received from client is not valid json: #{data.inspect}") diff --git a/lib/runner/connection.rb b/lib/runner/connection.rb index 36467f3b..c1dd99f5 100644 --- a/lib/runner/connection.rb +++ b/lib/runner/connection.rb @@ -43,7 +43,7 @@ class Runner::Connection end # Send arbitrary data in the WebSocket connection - def send(raw_data) + def send_data(raw_data) encoded_message = encode(raw_data) Rails.logger.debug { "#{Time.zone.now.getutc}: Sending to #{@socket.url}: #{encoded_message.inspect}" } @socket.send(encoded_message) diff --git a/lib/runner/strategy/docker_container_pool.rb b/lib/runner/strategy/docker_container_pool.rb index aae831cd..bf0fbe96 100644 --- a/lib/runner/strategy/docker_container_pool.rb +++ b/lib/runner/strategy/docker_container_pool.rb @@ -64,7 +64,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy socket = Connection.new(websocket_url, self, event_loop) begin Timeout.timeout(@execution_environment.permitted_execution_time) do - socket.send(command) + socket.send_data(command) yield(socket) event_loop.wait event_loop.stop