{"record":{"id":"ec2ad06f92de1e72","repo":"fluent/fluentd","slug":"bug-cannot-create-connection-for-udp","errorCode":null,"errorMessage":"BUG: cannot create connection for UDP","messagePattern":"BUG: cannot create connection for UDP","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/fluent/plugin_helper/server.rb","lineNumber":76,"sourceCode":"      CONNECTION_PROTOCOLS = [:tcp, :tls, :unix]\n\n      # server_create_connection(:title, @port) do |conn|\n      #   # on connection\n      #   source_addr = conn.remote_host\n      #   source_port = conn.remote_port\n      #   conn.data do |data|\n      #     # on data\n      #     conn.write resp # ...\n      #     conn.close\n      #   end\n      # end\n      def server_create_connection(title, port, proto: nil, bind: '0.0.0.0', shared: true, backlog: nil, tls_options: nil, **socket_options, &block)\n        proto ||= (@transport_config && @transport_config.protocol == :tls) ? :tls : :tcp\n\n        raise ArgumentError, \"BUG: title must be a symbol\" unless title && title.is_a?(Symbol)\n        raise ArgumentError, \"BUG: port must be an integer\" unless port && port.is_a?(Integer)\n        raise ArgumentError, \"BUG: invalid protocol name\" unless PROTOCOLS.include?(proto)\n        raise ArgumentError, \"BUG: cannot create connection for UDP\" unless CONNECTION_PROTOCOLS.include?(proto)\n\n        raise ArgumentError, \"BUG: tls_options is available only for tls\" if tls_options && proto != :tls\n\n        raise ArgumentError, \"BUG: block not specified which handles connection\" unless block_given?\n        raise ArgumentError, \"BUG: block must have just one argument\" unless block.arity == 1\n\n        if proto == :tcp || proto == :tls\n          socket_options[:linger_timeout] ||= @transport_config&.linger_timeout || 0\n        end\n\n        socket_options[:receive_buffer_size] ||= @transport_config&.receive_buffer_size\n\n        socket_option_validate!(proto, **socket_options)\n        socket_option_setter = ->(sock){ socket_option_set(sock, **socket_options) }\n\n        case proto\n        when :tcp\n          server = server_create_for_tcp_connection(shared, bind, port, backlog, socket_option_setter, &block)","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin_helper/server.rb#L58-L94","documentation":"ArgumentError from server_create_connection. Connection-style servers are only possible for CONNECTION_PROTOCOLS = [:tcp, :tls, :unix]; UDP is datagram-based and has no per-connection lifecycle, so proto: :udp is rejected even though :udp is a valid protocol for the helper's datagram APIs.","triggerScenarios":"server_create_connection(:my_udp, 5160, proto: :udp) { |conn| ... } - the caller asks for a connection server over UDP.","commonSituations":"Plugin authors reusing a TCP connection template and flipping proto to :udp; misunderstanding that in_udp-style sources are datagram services, not connection servers.","solutions":["Use the datagram APIs instead: server_create(:my_udp, port: 5160, proto: :udp) { |data, sock| ... } or server_create_udp_service","If connection semantics (connect/close/write per peer) are genuinely required, switch the design to proto: :tcp or :tls"],"exampleFix":"# before\nserver_create_connection(:my_udp, 5160, proto: :udp) do |conn|\n  ...\nend\n\n# after\nserver_create(:my_udp, port: 5160, proto: :udp) do |data, sock|\n  sock.write(\"echo: #{data}\")\nend","handlingStrategy":"type-guard","validationCode":"raise ArgumentError, 'use server_create for udp' if proto == :udp\nserver_create_connection(title, port, proto: proto) { |conn| ... }","typeGuard":"def connection_capable?(proto)\n  %i[tcp tls unix].include?(proto)\nend\n\n# usage\nif connection_capable?(proto)\n  server_create_connection(title, port, proto: proto, &block)\nelse\n  server_create(title, port: port, proto: proto, &datagram_block)\nend","tryCatchPattern":null,"preventionTips":["Branch on protocol before choosing the server API: connection APIs for tcp/tls/unix, datagram APIs for udp","Cover both branches in plugin tests"],"tags":["fluentd","server","udp","argument-error","plugin-helper"],"backgroundTag":"connectionless-protocol-misuse","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}