Skip to content

in_unix: cause "[error]: #0 unexpected error in json payload error" or "[warn]: #0 incoming data is broken" with huge data #4692

Closed
@Watson1978

Description

@Watson1978

Describe the bug

When it send the very long data at once from the client, it causes error with JSON data or warning with MessagePack format.
In my environment, this always happens when I send more than 256 KB at once.

To Reproduce

It just sends data using following code

# frozen_string_literal: true
require "socket"
require "json"
require "msgpack"

FORMAT = :json
UNIX_SOCKET_PATH = "/tmp/fluentd-unix.sock"

DATA_LENGTH = 1024 * 256

def data_generater
  d = ['test', Time.now.to_i, {"length_#{DATA_LENGTH}": "a" * DATA_LENGTH}]
  case FORMAT
  when :json
    d.to_json
  when :msgpack
    MessagePack.pack(d)
  else
    raise "unknown format: #{FORMAT}"
  end
end

begin
  s = UNIXSocket.new(UNIX_SOCKET_PATH)
  loop do
    data =
    s.send(data_generater, 0)
    sleep 1
  end
rescue Errno::EPIPE => e
  p e
ensure
  s&.close
end

client side

ruby unix_client.rb

Fluentd side

bundle exec bin/fluentd -c ~/socket_unix.conf --workers 1

Expected behavior

No errors

Your Environment

- Fluentd version: git master
- Package version:
- Operating system:
- Kernel version:

Your Configuration

<source>
  @type unix
  path /tmp/fluentd-unix.sock
</source>

<match **>
  @type file
  path /tmp/fluentd.log
</match>

Your Error Log

JSON

Send JSON data from client

$ bundle exec bin/fluentd -c ~/socket_unix.conf --workers 1
2024-11-02 09:44:04 +0900 [info]: init supervisor logger path=nil rotate_age=nil rotate_size=nil
2024-11-02 09:44:04 +0900 [info]: parsing config file is succeeded path="/home/watson/socket_unix.conf"
2024-11-02 09:44:04 +0900 [info]: gem 'fluentd' version '1.17.1'
2024-11-02 09:44:04 +0900 [warn]: define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2024-11-02 09:44:04 +0900 [info]: using configuration file: <ROOT>
  <source>
    @type unix
    path "/tmp/fluentd-unix.sock"
  </source>
  <match **>
    @type file
    path "/tmp/fluentd.log"
    <buffer time>
      path "/tmp/fluentd.log"
    </buffer>
  </match>
</ROOT>
2024-11-02 09:44:04 +0900 [info]: starting fluentd-1.17.1 pid=16001 ruby="3.3.5"
2024-11-02 09:44:04 +0900 [info]: spawn command to main:  cmdline=["/home/watson/.rbenv/versions/3.3.5/bin/ruby", "-r/home/watson/.rbenv/versions/3.3.5/lib/ruby/site_ruby/3.3.0/bundler/setup", "-Eascii-8bit:ascii-8bit", "bin/fluentd", "-c", "/home/watson/socket_unix.conf", "--workers", "1", "--under-supervisor"]
2024-11-02 09:44:04 +0900 [info]: #0 init worker0 logger path=nil rotate_age=nil rotate_size=nil
2024-11-02 09:44:04 +0900 [info]: adding match pattern="**" type="file"
2024-11-02 09:44:04 +0900 [info]: adding source type="unix"
2024-11-02 09:44:04 +0900 [warn]: #0 define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2024-11-02 09:44:04 +0900 [info]: #0 starting fluentd worker pid=16025 ppid=16001 worker=0
2024-11-02 09:44:04 +0900 [warn]: #0 Found existing '/tmp/fluentd-unix.sock'. Remove this file for in_unix plugin
2024-11-02 09:44:04 +0900 [info]: #0 listening fluent socket on /tmp/fluentd-unix.sock
2024-11-02 09:44:04 +0900 [info]: #0 fluentd worker is now running worker=0
2024-11-02 09:44:07 +0900 [error]: #0 unexpected error in json payload error="lexical error: invalid string in json text.\n                                     [\"test\",1730508247,{\"length_26214\n                     (right here) ------^\n"
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/src/fluentd/lib/fluent/plugin/in_unix.rb:175:in `<<'
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/src/fluentd/lib/fluent/plugin/in_unix.rb:175:in `on_read_json'
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/cool.io-1.9.0/lib/cool.io/io.rb:123:in `on_readable'
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/cool.io-1.9.0/lib/cool.io/io.rb:186:in `on_readable'
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/cool.io-1.9.0/lib/cool.io/loop.rb:88:in `run_once'
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/cool.io-1.9.0/lib/cool.io/loop.rb:88:in `run'
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/src/fluentd/lib/fluent/plugin_helper/event_loop.rb:93:in `block in start'
  2024-11-02 09:44:07 +0900 [error]: #0 /home/watson/src/fluentd/lib/fluent/plugin_helper/thread.rb:78:in `block in thread_create'

MessagePack

Send MessagePack data from client

$ bundle exec bin/fluentd -c ~/socket_unix.conf --workers 1
2024-11-02 09:45:01 +0900 [info]: init supervisor logger path=nil rotate_age=nil rotate_size=nil
2024-11-02 09:45:01 +0900 [info]: parsing config file is succeeded path="/home/watson/socket_unix.conf"
2024-11-02 09:45:01 +0900 [info]: gem 'fluentd' version '1.17.1'
2024-11-02 09:45:01 +0900 [warn]: define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2024-11-02 09:45:01 +0900 [info]: using configuration file: <ROOT>
  <source>
    @type unix
    path "/tmp/fluentd-unix.sock"
  </source>
  <match **>
    @type file
    path "/tmp/fluentd.log"
    <buffer time>
      path "/tmp/fluentd.log"
    </buffer>
  </match>
</ROOT>
2024-11-02 09:45:01 +0900 [info]: starting fluentd-1.17.1 pid=16161 ruby="3.3.5"
2024-11-02 09:45:01 +0900 [info]: spawn command to main:  cmdline=["/home/watson/.rbenv/versions/3.3.5/bin/ruby", "-r/home/watson/.rbenv/versions/3.3.5/lib/ruby/site_ruby/3.3.0/bundler/setup", "-Eascii-8bit:ascii-8bit", "bin/fluentd", "-c", "/home/watson/socket_unix.conf", "--workers", "1", "--under-supervisor"]
2024-11-02 09:45:01 +0900 [info]: #0 init worker0 logger path=nil rotate_age=nil rotate_size=nil
2024-11-02 09:45:01 +0900 [info]: adding match pattern="**" type="file"
2024-11-02 09:45:01 +0900 [info]: adding source type="unix"
2024-11-02 09:45:01 +0900 [warn]: #0 define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2024-11-02 09:45:01 +0900 [info]: #0 starting fluentd worker pid=16185 ppid=16161 worker=0
2024-11-02 09:45:01 +0900 [warn]: #0 Found existing '/tmp/fluentd-unix.sock'. Remove this file for in_unix plugin
2024-11-02 09:45:01 +0900 [info]: #0 listening fluent socket on /tmp/fluentd-unix.sock
2024-11-02 09:45:01 +0900 [info]: #0 fluentd worker is now running worker=0
2024-11-02 09:45:04 +0900 [warn]: #0 incoming data is broken: msg=97
2024-11-02 09:45:04 +0900 [warn]: #0 incoming data is broken: msg=97
2024-11-02 09:45:04 +0900 [warn]: #0 incoming data is broken: msg=97
2024-11-02 09:45:04 +0900 [warn]: #0 incoming data is broken: msg=97
2024-11-02 09:45:04 +0900 [warn]: #0 incoming data is broken: msg=97
--- (snip) ---

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions