diff --git a/lib/fluent/plugin/in_tcp.rb b/lib/fluent/plugin/in_tcp.rb index 428eb5258a..71d77b0f4f 100644 --- a/lib/fluent/plugin/in_tcp.rb +++ b/lib/fluent/plugin/in_tcp.rb @@ -55,13 +55,12 @@ def multi_workers_ready? def start super - @buffer = '' server_create(:in_tcp_server, @port, bind: @bind) do |data, conn| - @buffer << data + conn.buffer << data begin pos = 0 - while i = @buffer.index(@delimiter, pos) - msg = @buffer[pos...i] + while i = conn.buffer.index(@delimiter, pos) + msg = conn.buffer[pos...i] pos = i + @delimiter.length @parser.parse(msg) do |time, record| @@ -77,7 +76,7 @@ def start router.emit(tag, time, record) end end - @buffer.slice!(0, pos) if pos > 0 + conn.buffer.slice!(0, pos) if pos > 0 end end end diff --git a/lib/fluent/plugin_helper/server.rb b/lib/fluent/plugin_helper/server.rb index ffdb57dab1..eb57832475 100644 --- a/lib/fluent/plugin_helper/server.rb +++ b/lib/fluent/plugin_helper/server.rb @@ -425,9 +425,12 @@ def on(event, &callback) end class TCPCallbackSocket < CallbackSocket + attr_accessor :buffer + def initialize(sock) super("tcp", sock, [:data, :write_complete, :close]) @peeraddr = @sock.peeraddr + @buffer = '' end def write(data)