From 1891cdd69c28de710f3576e8a7134871633f7144 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 11 Oct 2021 23:15:36 +0200 Subject: [PATCH] Add check whether buffer is empty --- lib/runner/connection.rb | 2 +- lib/runner/connection/buffer.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/runner/connection.rb b/lib/runner/connection.rb index 5619bf2d..03368ab7 100644 --- a/lib/runner/connection.rb +++ b/lib/runner/connection.rb @@ -112,7 +112,7 @@ class Runner::Connection def on_close(_event) Rails.logger.debug { "#{Time.zone.now.getutc}: Closing connection to #{@socket.url} with status: #{@status}" } - forward_message @buffer.flush + forward_message @buffer.flush unless @buffer.empty? # Depending on the status, we might want to destroy the runner at management. # This ensures we get a new runner on the next request. diff --git a/lib/runner/connection/buffer.rb b/lib/runner/connection/buffer.rb index 82dc1006..c7dcba87 100644 --- a/lib/runner/connection/buffer.rb +++ b/lib/runner/connection/buffer.rb @@ -38,6 +38,10 @@ class Runner::Connection::Buffer remaining_buffer end + def empty? + @line_buffer.empty? && @global_buffer.empty? + end + private def process_and_split(message_parts, stop: false)