Skip to content

Naive inbound: raw connection passed to router bypasses HTTP2Wrapper mutex #4249

Description

@jys1670

Operating system

Linux

System version

NixOS 26.11 (unstable)

Installation type

Others

If you are using a graphical client, please provide the version of the client.

No response

Version

sing-box version 1.13.14

Environment: go1.26.4 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,with_ocm,badlinkname,tfogo_checklinkname0,with_naive_outbound
CGO: enabled

Description

In protocol/naive/inbound.go, NewHTTP2Wrapper(conn) is initialized but the wrapper is never actually passed to the router:

	if !waitForClose {
		n.router.RouteConnectionEx(ctx, conn, metadata, nil)
	} else {
		done := make(chan struct{})
		wrapper := v2rayhttp.NewHTTP2Wrapper(conn) // Created here to provide mutex protection
		n.router.RouteConnectionEx(ctx, conn, metadata, N.OnceClose(func(it error) { // But raw conn is passed instead of wrapper
			close(done)
		}))
		<-done
		wrapper.CloseWrapper()
	}

I believe this sometimes causes random data corruption.
Another DNS naive issue that may be related to this problem: #3987

Reproduction

Not sure how to reproduce, but under concurrent workloads, the connection feels more stable with wrapper fix

Logs

Supporter

Integrity requirements

  • I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • I confirm that I have provided the server and client configuration files and process that can be reproduced locally, instead of a complicated client configuration file that has been stripped of sensitive data.
  • I confirm that I have provided the simplest configuration that can be used to reproduce the error I reported, instead of depending on remote servers, TUN, graphical interface clients, or other closed-source software.
  • I confirm that I have provided the complete configuration files and logs, rather than just providing parts I think are useful out of confidence in my own intelligence.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions