Skip to content

Commit

Permalink
Don't error when trying to write a message to a closed client take 2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgxworld committed Jun 28, 2023
1 parent 034452c commit 3858552
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/message_bus/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/message_bus/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 3858552

Please sign in to comment.