From a0808f3aa8a619fe61650d862f5ebf2483bab79c Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 28 Jun 2023 10:41:39 +0800 Subject: [PATCH] Don't error when trying to write a message to a closed client take 2 (#339) This was first introduced in a2a46fde87f4c9c6cff806db5d84c2544befaa6d but reverted because a new MessageBus release broke production and we had to quickly revert before being able to isolate the commit. We have since tested this commit in isolation in production and confirm that MessageBus continues to work. When a client is set to use chunked encoding by setting `use_chunked` to true, trying to write a message to the client when the client has been closed will raise an error. This commit changes it such that we don't raise an error since the raised error doesn't do anything useful. --- CHANGELOG | 6 ++++++ lib/message_bus/client.rb | 2 +- lib/message_bus/version.rb | 2 +- spec/lib/message_bus/client_spec.rb | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 57da32a1..73a11b23 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +28-06-2023 + +- Version 4.3.6 + + - Don't error when trying to write a message to a closed client take 2 + 20-06-2023 - Version 4.3.5 diff --git a/lib/message_bus/client.rb b/lib/message_bus/client.rb index 8ef27509..50463fb9 100644 --- a/lib/message_bus/client.rb +++ b/lib/message_bus/client.rb @@ -278,7 +278,7 @@ def write_chunk(data) @async_response << data @async_response << postfix @async_response << NEWLINE - else + elsif @io @io.write(chunk_length.to_s(16) << NEWLINE << data << postfix << NEWLINE) end end diff --git a/lib/message_bus/version.rb b/lib/message_bus/version.rb index 60fb272e..a92df2f1 100644 --- a/lib/message_bus/version.rb +++ b/lib/message_bus/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MessageBus - VERSION = "4.3.5" + VERSION = "4.3.6" end diff --git a/spec/lib/message_bus/client_spec.rb b/spec/lib/message_bus/client_spec.rb index 139b7331..12c30f05 100644 --- a/spec/lib/message_bus/client_spec.rb +++ b/spec/lib/message_bus/client_spec.rb @@ -99,6 +99,12 @@ def parse_chunk(data) chunk2.length.must_equal 0 end + it "does not raise an error when trying to write a message to a closed client using chunked encoding" do + @client.use_chunked = true + assert(@client.closed?) + @client << MessageBus::Message.new(1, 1, "/test", "test") + end + it "does not bleed data across sites" do @client.site_id = "test"