Commit 946c655
authored
feat(network/onion): detect liveness via TcpStream close (#5168)
<!--
Thank you for contributing to nervosnetwork/ckb!
If you haven't already, please read
[CONTRIBUTING](https://github.com/nervosnetwork/ckb/blob/develop/CONTRIBUTING.md)
document.
If you're unsure about anything, just ask; somebody should be along to
answer within a day or two.
**Important**: We use Squash Merge to merge PRs, so the PR title will
become the commit message.
Please ensure your PR title follows the [Conventional Commit
Messages](https://www.conventionalcommits.org/) format.
The most important prefixes you should use:
- `fix:`: represents bug fixes, and results in a SemVer patch bump.
- `feat:`: represents a new feature, and results in a SemVer minor bump.
- `<prefix>!:` (e.g. `feat!:`): represents a breaking change (indicated
by the !) and results in a SemVer major bump.
Other conventional prefixes are also acceptable (e.g., `docs:`,
`refactor:`, `test:`, `chore:`, etc.).
-->
### What problem does this PR solve?
Issue Number: close #5161 <!-- REMOVE this line if no issue to close -->
Follow-up to #5271.
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.
### What is changed and how it works?
What's Changed:
- An `oneshot` channel notifies `TorController` when either copy
direction terminates (EOF or error).
- Replaced the 3-second ticker loop in `OnionService` with a branch
awaiting `wait_for_disconnect()`.
### Related changes
### Check List <!--REMOVE the items that are not applicable-->
Tests <!-- At least one of them must be included. -->
- [ ] Unit test
- [ ] Integration test
- [x] Manual test (add detailed scripts or steps below)
- [ ] No code
Manual test steps:
1. `ckb run` with config listen_on_onion = true.
2. Observe the onion service starts successfully.
3. Kill/exit the Tor process.
4. Verify the node logs `"Tor control connection lost"` within
milliseconds, not after a multi-second delay.
5. Restart the Tor daemon and verify the onion service can be
re-established.
Side effects
- ~~Performance regression~~
- ~~Breaking backward compatibility~~1 parent 8ddf15a commit 946c655
3 files changed
Lines changed: 33 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
147 | 140 | | |
148 | 141 | | |
149 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
| 219 | + | |
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
| |||
237 | 239 | | |
238 | 240 | | |
239 | 241 | | |
| 242 | + | |
240 | 243 | | |
241 | 244 | | |
242 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
243 | 255 | | |
244 | 256 | | |
245 | 257 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
104 | 114 | | |
105 | 115 | | |
106 | 116 | | |
| |||
0 commit comments