Skip to content

Commit

Permalink
Fix invalid message polluting subsequent message
Browse files Browse the repository at this point in the history
Signed-off-by: Satoshi Matsumoto <[email protected]>
  • Loading branch information
kaorimatz committed Dec 5, 2023
1 parent fd471f9 commit f13b289
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/fluent/logger/fluent_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ def to_msgpack(msg)
@packer.pack(msg).to_s
rescue NoMethodError
JSON.parse(JSON.generate(msg)).to_msgpack
ensure
@packer.clear
end
@packer.clear
res
}
end
Expand Down
4 changes: 4 additions & 0 deletions spec/fluent_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
expect(fluentd.queue.last).to be_nil
logger_io.rewind
logger_io.read =~ /FluentLogger: Can't convert to msgpack:/

logger.post('tag', { 'a' => 'b' })
fluentd.wait_transfer
expect(fluentd.queue.last).to eq ['logger-test.tag', { 'a' => 'b' }]
}

it ('should raise an error when second argument is non hash object') {
Expand Down

0 comments on commit f13b289

Please sign in to comment.