Repository navigation
fix(serve): rebuild the transport only when the paired set changes - #668
matthieu403 wants to merge 1 commit into
Conversation
avelino
left a comment
There was a problem hiding this comment.
Approving. The root cause is right: refresh_peer_direct_addr rewrites peers.json on every inbound connection, and a rebuild binds a new port that the other daemon then records, so the two keep rebuilding each other. Rebuilding only when the set of paired node ids changes breaks that loop.
I checked the points I was worried about. paired comes from transport.peers(), which is the same PeersStore::list() the file read gives, so the two sets can't drift apart and cause a rebuild loop. The baseline is taken before the build and the mtime is read before the file, so a write in between is not lost. Removal and a vanished file still cycle the transport. The catch-up loop does reload peers.json each tick, so skipping the rebuild for an address change is safe. I ran the 11 sync_supervisor tests, and with the set comparison disabled a_refreshed_peer_address_does_not_cycle_the_transport fails, so it does pin the fix. fmt, clippy and the file-size check are clean.
Nits, none blocking:
- The "unreadable
peers.jsonis not a change" branch has no test. - A few tests rely on
sleep(50ms)for the mtime to move. Fine on ext4, APFS and tmpfs, but only one of them asserts it moved.
Before merge it needs a rebase: CHANGELOG.md conflicts in ### Fixed. Thanks for the careful repro table in the description.
`outl serve` rebuilt its transport on every write to `peers.json`. The transport writes there itself: each inbound connection records the address the peer connected from. A rebuild binds a new port, so two paired daemons recorded each other's new port and rebuilt in turn, every few seconds, without end. Each rebuild closes every connection, which kept a third device on a slow link from finishing its first sync. The supervisor still watches the file's mtime, but only to re-read it: it rebuilds when the set of paired node ids is no longer the one the transport was built with (a pairing, a removal, a peer learned from membership gossip). An address needs no rebuild, the catch-up loop reloads `peers.json` on every tick. The tests move to `sync_supervisor_tests.rs` to keep the file under the 600-line ratchet. Fixes outlmd#630
e72998c to
a84a6b9
Compare
|
Rebased on main. Thanks for the review. |
What this PR does
Two paired
outl servedaemons rebuild their transport every few seconds, forever, and a device that has just joined cannot finish its first sync while they do (#630).The supervisor rebuilds on every write to
peers.json, and the transport writes there itself: each inbound connection records the address the peer connected from.A rebuild binds a new port, the other daemon records it, and that write rebuilds it in turn.
The supervisor now rebuilds only when the set of paired node ids differs from the one the transport was built with.
The mtime stays as the cheap gate for re-reading the file.
A pairing, a removal and a peer learned from membership gossip still cycle the transport; a refreshed address does not, and does not need to, since the catch-up loop reloads
peers.jsonon every tick.It is one file of behaviour,
crates/outl-cli/src/cmd/sync_supervisor.rs.The rest of the diff is the test module moving to
sync_supervisor_tests.rs: the three new tests took the file past the 600-line ratchet.How to verify
cargo test -p outl-cli cargo clippy -p outl-cli --all-targets -- -D warnings cargo fmt --all -- --check scripts/check-file-size.shAll pass.
a_refreshed_peer_address_does_not_cycle_the_transportfails when the set comparison is taken out.I did not run the whole workspace test suite.
With the real binary, the scenario of #630 (A and B on a fast link, C new and empty behind 5 Mbit/s and 20 ms, three
outl serve, no Internet):B and C each rebuilt once on this branch, when membership gossip told each about the other. That is a new paired device, so it is the rebuild the watch exists for.
Related issues / docs
Closes #630
Updated docs:
docs/cli.md(theoutl servesection),crates/outl-cli/CLAUDE.md.CHANGELOG.md[Unreleased]has an entry.Anything reviewers should look at carefully
peers.jsonthat cannot be read or parsed is not treated as a change, same as an unreadable mtime today. The baseline is left where it was, so the file is read again on the next tick (1 s).Out of scope for this PR
.mdfiles listed under "Also observed" in Two pairedoutl servedaemons rebuild their transport every few seconds, so a new device never finishes its first sync #630. I have not checked whether they come from the loop.outl syncgiving up after about 6 seconds and exiting 0 with0/1 peer(s) reachable.This PR has been co-written with Claude Code.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.