Skip to content

face: make UnicastTCPTransport.Close() non-blocking - #229

Merged
tianyuan129 merged 2 commits into
named-data:mainfrom
yoursunny:fix/unicast-tcp-close-deadlock
Oct 19, 2026
Merged

tianyuan129 merged 2 commits into
named-data:mainfrom
yoursunny:fix/unicast-tcp-close-deadlock

Conversation

@yoursunny

@yoursunny yoursunny commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Close() performs an unconditional blocking send on rechan. If a previous Close() already queued the signal while runReceive exited without receiving it (e.g. mgmt faces/destroy followed by the deferred Close in runReceive), the second send blocks forever: the receive/send goroutines leak, the face table entry is never removed, and the face expiration sweeper wedges on the same channel, stopping expiration for all on-demand faces.

Use a non-blocking send so repeated Close() calls are safe.

Note: this bug was identified and patch generated by https://muse.ai but the submitter has reviewed the code.

yoursunny and others added 2 commits October 15, 2026 08:59
Close() performs an unconditional blocking send on rechan. If a previous
Close() already queued the signal while runReceive exited without
receiving it (e.g. mgmt faces/destroy followed by the deferred Close in
runReceive), the second send blocks forever: the receive/send goroutines
leak, the face table entry is never removed, and the face expiration
sweeper wedges on the same channel, stopping expiration for all
on-demand faces.

Use a non-blocking send so repeated Close() calls are safe.
@tianyuan129
tianyuan129 merged commit d37de74 into named-data:main Oct 19, 2026
9 checks passed
@yoursunny

Copy link
Copy Markdown
Member Author

A bit of information on how to demonstrate the effect of this bug:

# console A
sudo ./ndnd fw run ./fw/yanfd.sample.yml

# console B
NDN_CLIENT_TRANSPORT=tcp://127.0.0.1:6363 ndnping /A

# console C
nfdc face # find the TCP face of ndnping
nfdc face 8 # use the FaceID identified

# console A: press CTRL+C

Without the fix, NDNd forwarder cannot exit upon CTRL+C.
The fix solves this problem.

@yoursunny
yoursunny deleted the fix/unicast-tcp-close-deadlock branch October 19, 2026 23:21
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