feat(network/onion): detect liveness via TcpStream close#5168
Open
jetjinser wants to merge 1 commit intonervosnetwork:developfrom
Open
feat(network/onion): detect liveness via TcpStream close#5168jetjinser wants to merge 1 commit intonervosnetwork:developfrom
jetjinser wants to merge 1 commit intonervosnetwork:developfrom
Conversation
instead of polling
eval-exec
reviewed
Apr 14, 2026
| debug!("Tor DuplexStream exited."); | ||
| }); | ||
|
|
||
| let mut utc: UnauthenticatedConn<_> = UnauthenticatedConn::new(client); |
Collaborator
There was a problem hiding this comment.
UnauthenticatedConn<_>
Could UnauthenticatedConn replace _ with the real inner type?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: close #5161
Problem Summary:
The onion service currently polls the Tor daemon every 3 seconds via
get_uptime()to detect connection loss. This adds unnecessary latency (up to 3s for failure detection) and constant I/O overhead. A passive, event-driven approach would react instantly and reduce resource usage.P.S. This implementation represents the cleanest approach I could devise given the constraints of the existing
torutcontroller API. If there is a more idiomatic or efficient way to monitor the underlying TcpStream liveness, I am open to feedback and happy to revise this PR accordingly.What is changed and how it works?
What's Changed:
tokio::io::duplexas an in-memory proxy betweenTcpStreamand theTorControl.copybetween the TCP socket and the duplex stream.mpscchannel notifiesTorControllerwhen either copy direction terminates (EOF or error).OnionServicewith a branch awaitingwait_for_disconnect().Related changes
Check List
Tests
Manual test steps:
ckb runwith config listen_on_onion = true."Tor control connection lost"within milliseconds, not after a multi-second delay.Side effects
Performance regressionBreaking backward compatibility