Skip to content

Commit

Permalink
Merge pull request #98 from kaorimatz/fix-message-pollution
Browse files Browse the repository at this point in the history
Fix invalid message polluting subsequent message
  • Loading branch information
ashie committed Dec 14, 2023
2 parents fd471f9 + f13b289 commit cb7f00e
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 cb7f00e

Please sign in to comment.