fluent/fluentd · error · ArgumentError

BUG: invalid protocol name

Error message

BUG: invalid protocol name

What it means

ArgumentError from server_create_connection in the server plugin helper. The proto: keyword is validated against PROTOCOLS = [:tcp, :udp, :tls, :unix]; anything else - a string 'tcp', :tcp4, :TLS, :sctp - is a caller bug (hence the 'BUG:' prefix), because the helper can only create sockets for the known protocols.

Source

Thrown at lib/fluent/plugin_helper/server.rb:75

      PROTOCOLS = [:tcp, :udp, :tls, :unix]
      CONNECTION_PROTOCOLS = [:tcp, :tls, :unix]

      # server_create_connection(:title, @port) do |conn|
      #   # on connection
      #   source_addr = conn.remote_host
      #   source_port = conn.remote_port
      #   conn.data do |data|
      #     # on data
      #     conn.write resp # ...
      #     conn.close
      #   end
      # end
      def server_create_connection(title, port, proto: nil, bind: '0.0.0.0', shared: true, backlog: nil, tls_options: nil, **socket_options, &block)
        proto ||= (@transport_config && @transport_config.protocol == :tls) ? :tls : :tcp

        raise ArgumentError, "BUG: title must be a symbol" unless title && title.is_a?(Symbol)
        raise ArgumentError, "BUG: port must be an integer" unless port && port.is_a?(Integer)
        raise ArgumentError, "BUG: invalid protocol name" unless PROTOCOLS.include?(proto)
        raise ArgumentError, "BUG: cannot create connection for UDP" unless CONNECTION_PROTOCOLS.include?(proto)

        raise ArgumentError, "BUG: tls_options is available only for tls" if tls_options && proto != :tls

        raise ArgumentError, "BUG: block not specified which handles connection" unless block_given?
        raise ArgumentError, "BUG: block must have just one argument" unless block.arity == 1

        if proto == :tcp || proto == :tls
          socket_options[:linger_timeout] ||= @transport_config&.linger_timeout || 0
        end

        socket_options[:receive_buffer_size] ||= @transport_config&.receive_buffer_size

        socket_option_validate!(proto, **socket_options)
        socket_option_setter = ->(sock){ socket_option_set(sock, **socket_options) }

        case proto
        when :tcp

View on GitHub (pinned to dd45c6e18d)

Solutions

  1. Pass one of the symbols :tcp, :udp, :tls, :unix
  2. Normalize config strings first: proto.to_s.downcase.to_sym
  3. When nil is acceptable, omit proto: and let the transport config decide (:tls for <transport tls>, else :tcp)

Example fix

# before
server_create_connection(:in_http, 24224, proto: 'tcp') { |conn| ... }

# after
server_create_connection(:in_http, 24224, proto: :tcp) { |conn| ... }
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, 'proto must be tcp/udp/tls/unix' unless %i[tcp udp tls unix].include?(proto)
server_create_connection(title, port, proto: proto) { |conn| ... }

Type guard

def valid_server_protocol?(proto)
  %i[tcp udp tls unix].include?(proto)
end

Try / catch

begin
  server_create_connection(title, port, proto: proto) { |conn| ... }
rescue ArgumentError => e
  raise ArgumentError, "plugin bug: #{e.message} (proto=#{proto.inspect})"
end

Prevention

When it happens

Trigger: server_create_connection(:my_title, 24224, proto: :tcp4), proto: 'tcp' (string instead of symbol), or a misspelled symbol like :tlss. Note proto defaults to :tls when the plugin's @transport_config protocol is tls, otherwise :tcp, so the invalid value must have been passed explicitly.

Common situations: Plugin authors accepting a protocol string from config and passing it through without normalizing; porting code from another library that uses strings or protocol families like :tcp4/:tcp6.

Related errors


AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21). Data as JSON: /api/errors/d117c977e15a38fa. Report an issue: GitHub.