Skip to content

Commit

Permalink
in_tcp: Add message_length_limit
Browse files Browse the repository at this point in the history
Add the same feature to `in_tcp` as `message_length_limit` in
`in_udp`, to drop too large incoming data.

If there is subsequent data, that part may fail to parse and
warning log is output, but this fix considers it a specification.

Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Apr 10, 2023
1 parent 24c8bdd commit 47463b6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/fluent/plugin/in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class TcpInput < Input
desc "The field name of the client's address."
config_param :source_address_key, :string, default: nil

# Setting default to nil for backward compatibility
desc "The max bytes of message."
config_param :message_length_limit, :size, default: nil

config_param :blocking_timeout, :time, default: 0.5

desc 'The payload is read up to this character.'
Expand Down Expand Up @@ -111,6 +115,11 @@ def start

conn.buffer << data
buf = conn.buffer
if !@message_length_limit.nil? && @message_length_limit < buf.bytesize
log.info "The receiving data is larger than 'message_length_limit', dropped:", limit: @message_length_limit, size: buf.bytesize, head: buf[...32]
buf.clear
next
end
pos = 0
while i = buf.index(@delimiter, pos)
msg = buf[pos...i]
Expand Down Expand Up @@ -141,6 +150,11 @@ def start

conn.buffer << data
buf = conn.buffer
if !@message_length_limit.nil? && @message_length_limit < buf.bytesize
log.info "The receiving data is larger than 'message_length_limit', dropped:", limit: @message_length_limit, size: buf.bytesize, head: buf[...32]
buf.clear
next
end
pos = 0
es = Fluent::MultiEventStream.new
while i = buf.index(@delimiter, pos)
Expand Down

0 comments on commit 47463b6

Please sign in to comment.