Skip to content

Fix: keep a replaced UDP session when the old one ends - #3874

Open
b84330808 wants to merge 1 commit into
v2fly:masterfrom
b84330808:fix-udp-worker-stale-removal
Open

b84330808 wants to merge 1 commit into
v2fly:masterfrom
b84330808:fix-udp-worker-stale-removal

Conversation

@b84330808

Copy link
Copy Markdown

Fixes #3777.

When a UDP session ends, the next packet from the same source creates a replacement udpConn under the same connID. The old session's goroutine then called removeConn(id), which deleted whatever was stored under that key, i.e. the replacement. The replacement then runs outside activeConn. If the checker has stopped (it stops when a tick finds the map empty), the next new connection runs clean() synchronously from checker.Start(). A stale delete landing between getConnection and that clean() leaves the map empty, and common.Must panics with no more connections. stopping..., the frame in #3777.

removeConn now deletes only while the map still holds that same connection. That also covers what the inactive flag from #1305 handled (the checker already removed the conn), so the flag, which was written under the worker lock but read without it, is gone. This follows the direction sketched in #3777 but keeps the checker lifecycle unchanged.

TestUDPWorkerEndedSessionKeepsReplacementConn drives two sessions from one source through callback and checks that ending the first leaves the second registered. It fails on master and passes with this change. A local stress loop (one source, short checker interval) hit the same panic within milliseconds on master and ran 8M packets over 10 s without it after the change. go test -race -count=3 ./app/proxyman/inbound/ is clean on Linux.

When a UDP session ends, a new packet from the same source creates a
replacement connection under the same key. The old session's goroutine
then deleted that key unconditionally, removing the replacement it did
not own. The replacement kept running outside the map, and if the
checker was stopped, the next new connection's synchronous cleanup could
find the map empty and panic in common.Must with
"no more connections. stopping..." (v2fly#3777).

Remove a connection only while it is still the one registered for its
key. This also covers the case the inactive flag handled (the checker
already removed it), so drop that unsynchronized flag.
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.

panic: app/proxyman/inbound: no more connections. stopping...

1 participant