From dfdec92c6e4a5e7f45e8a0e62ddf66a511a3f9f1 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sat, 30 Oct 2021 12:26:16 +0200 Subject: [PATCH] Use ping option only for DCP WebSocket * The Faye::WebSocket library will "buffer" some output of the connection and emit the `on :message` events in the order of the messages. However, when a ping is sent while the connection has already been closed, it will emit the `on :close` event immediately and drop all other messages (in that "buffer"). This is problematic for very short running executions that generate a long output (as this will be cut off without a proper exit message sent by Poseidon). --- lib/runner/connection.rb | 6 +----- lib/runner/strategy/docker_container_pool.rb | 6 +++++- lib/runner/strategy/poseidon.rb | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/runner/connection.rb b/lib/runner/connection.rb index 150c7cb5..87f59aac 100644 --- a/lib/runner/connection.rb +++ b/lib/runner/connection.rb @@ -18,11 +18,7 @@ class Runner::Connection def initialize(url, strategy, event_loop, locale = I18n.locale) Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Opening connection to #{url}" } - # The `ping` value is measured in seconds and specifies how often a Ping frame should be sent. - # Internally, Faye::WebSocket uses EventMachine and the `ping` value is used to wake the EventMachine thread - # The `tls` option is used to customize the validation of TLS connections. - # Passing `nil` as a `root_cert_file` is okay and done so for the DockerContainerPool. - @socket = Faye::WebSocket::Client.new(url, [], strategy.class.websocket_header.merge(ping: 0.1)) + @socket = Faye::WebSocket::Client.new(url, [], strategy.class.websocket_header) @strategy = strategy @status = :established @event_loop = event_loop diff --git a/lib/runner/strategy/docker_container_pool.rb b/lib/runner/strategy/docker_container_pool.rb index 72b76d92..fe45d23c 100644 --- a/lib/runner/strategy/docker_container_pool.rb +++ b/lib/runner/strategy/docker_container_pool.rb @@ -129,7 +129,11 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy end def self.websocket_header - {} + # The `ping` value is measured in seconds and specifies how often a Ping frame should be sent. + # Internally, Faye::WebSocket uses EventMachine and the `ping` value is used to wake the EventMachine thread + { + ping: 0.1, + } end private diff --git a/lib/runner/strategy/poseidon.rb b/lib/runner/strategy/poseidon.rb index 781a4b2a..cabda9f5 100644 --- a/lib/runner/strategy/poseidon.rb +++ b/lib/runner/strategy/poseidon.rb @@ -118,6 +118,8 @@ class Runner::Strategy::Poseidon < Runner::Strategy end def self.websocket_header + # The `tls` option is used to customize the validation of TLS connections. + # The `headers` option is used to pass the `Poseidon-Token` as part of the initial connection request. { tls: {root_cert_file: config[:ca_file]}, headers: {'Poseidon-Token' => config[:token]},