Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chunk format check in in_forward #611

Merged
merged 1 commit into from
Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/fluent/plugin/in_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ def on_message(msg, chunk_size, source)
return
end

# TODO format error
# TODO: raise an exception if broken chunk is generated by recoverable situation
unless msg.is_a?(Array)
log.warn "incoming chunk is broken:", source: source, msg: msg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg should be inspect -ed for various values, ex: strings with escape code or others.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspect is done in log methods.

message << " #{k}=#{v.inspect}"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, okay.

return
end

tag = msg[0].to_s
entries = msg[1]

Expand Down
20 changes: 20 additions & 0 deletions test/plugin/test_in_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ def test_send_large_chunk_limit
}.size == 1, "large chunk warning is not logged"
end

data('string chunk' => 'broken string',
'integer chunk' => 10)
def test_send_broken_chunk(data)
d = create_driver

# d.run => send_data
d.run do
d.instance.send(:on_message, data, 1000000000, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000")
end

# check emitted data
emits = d.emits
assert_equal 0, emits.size

# check log
assert d.instance.log.logs.select{|line|
line =~ / \[warn\]: incoming chunk is broken: source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" msg=#{data.inspect}/
}.size == 1, "should not accept broken chunk"
end

def test_respond_to_message_requiring_ack
d = create_driver

Expand Down