fix(discovery): survive a peer disconnecting mid-session - #3
Merged
Merged
Conversation
6 tasks done
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 changes
The scanner no longer dies when a beacon it discovered goes away.
DiscoveryDHTattached an error handler to the raw Hyperswarm connection butnot to the
FramedStreamwrapping it. When a peer disconnected, the streamemitted an unhandled
'error'and took the whole process down:One line:
frames.on('error', () => {}), alongside the handler the connectionalready had. A peer going away is normal in P2P, not exceptional.
Why
peer-lostalready worked — the scanner removed the beacon and rendered"No beacons nearby yet...". Then it crashed a moment later, so in practice a
traveler's session ended every time a shop closed its terminal.
Verified
Two instances with separate storage, full cycle:
ID: 0550aef8749b...ECONNRESET, process still runningID: bbddb59bf01f...pnpm run lint— exit 0pnpm test— 4/4 tests, 5/5 assertsNot addressed here
A restarted beacon comes back with a new id, because
getStorageDir()inbackend/index.jssuffixes the corestore path withprocess.pid. The same shopreads as a different peer after every restart, and storage grows without bound.
Worth a separate change.