Skip to content

fix: do not cache zero-byte closed connections in sniffer skipList - #3550

Merged
wwqgtxx merged 1 commit into
MetaCubeX:Alphafrom
semanym:fix/sniffer-skip-list-zero-byte-eof
Nov 30, 2026
Merged

wwqgtxx merged 1 commit into
MetaCubeX:Alphafrom
semanym:fix/sniffer-skip-list-zero-byte-eof

Conversation

@semanym

@semanym semanym commented Nov 30, 2026

Copy link
Copy Markdown

Summary

Prevents connections that close or are canceled before sending any application bytes (such as speculative browser pre-connects or Happy Eyeballs races) from poisoning Dispatcher.skipList for a shared dstIP:port.

Root Cause

In component/sniffer/dispatcher.go, Dispatcher.TCPSniff incremented skipList[dstIP:port] on every error returned by sniffDomain. When a client opens a TCP connection and closes it immediately without sending any bytes, the initial conn.Peek(1) fails with io.EOF (or another closed/canceled error) while conn.Buffered() == 0. Six such empty connections exceeded the threshold (count > 5) and disabled SNI sniffing for all domains sharing that IP:port for the full 600 s TTL.

Changes

  • component/sniffer/dispatcher.go: Add shouldCacheSniffFailure(conn, err) so TCPSniff skips cacheSniffFailed when conn.Buffered() == 0 and the error is a closed or canceled connection (E.IsClosed(err), io.ErrUnexpectedEOF, or context.Canceled). Server-first read timeouts (os.ErrDeadlineExceeded), unrecognized payloads, and truncated non-empty payloads continue to be cached as before.
  • component/sniffer/dispatcher_test.go: Add TestDispatcherSkipList covering zero-byte EOF / ErrUnexpectedEOF / net.ErrClosed / ECONNRESET / context.Canceled, unrecognized payloads, server-first read timeouts, truncated payload followed by EOF, and partial failure recovery.

Verification

  • go test -race -count=1 ./component/sniffer/...
  • go test -race -count=1 -tags "with_gvisor" ./component/sniffer/...
  • go vet ./component/sniffer/... (darwin, linux, windows)

Fixes #3527

🤖 Generated with Claude Code

In Dispatcher.TCPSniff, any error returned by sniffDomain incremented
skipList[dstIP:port], including connections that closed or were canceled
before sending a single application byte (such as speculative browser
pre-connects or Happy Eyeballs races). Six such zero-byte closures
disabled SNI sniffing for all domains sharing that IP:port for the full
600 s TTL.

Skip caching the failure when conn.Buffered() == 0 and the error is a
connection-closed or cancellation error (io.EOF, io.ErrUnexpectedEOF,
net.ErrClosed, syscall.ECONNRESET, context.Canceled, etc.), while still
counting server-first read timeouts (os.ErrDeadlineExceeded) and
unrecognized or truncated payloads.

Fixes MetaCubeX#3527

Co-Authored-By: Claude Code <noreply@anthropic.com>
@wwqgtxx
wwqgtxx merged commit faf5a5e into MetaCubeX:Alpha Nov 30, 2026
135 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants