Skip to content

fix(discovery): survive a peer disconnecting mid-session - #3

Merged
XxHugheadxX merged 1 commit into
mainfrom
fix/discovery-crash
Aug 25, 2026
Merged

XxHugheadxX merged 1 commit into
mainfrom
fix/discovery-crash

Conversation

@XxHugheadxX

Copy link
Copy Markdown
Contributor

What changes

The scanner no longer dies when a beacon it discovered goes away.

DiscoveryDHT attached an error handler to the raw Hyperswarm connection but
not to the FramedStream wrapping it. When a peer disconnected, the stream
emitted an unhandled 'error' and took the whole process down:

Uncaught Error: connection reset by peer
    at WritableState.afterDestroy (node_modules/streamx/index.js:572:19)
    at FramedStream._destroy (node_modules/streamx/index.js:725:5)
  code: 'ECONNRESET'

One line: frames.on('error', () => {}), alongside the handler the connection
already had. A peer going away is normal in P2P, not exceptional.

Why

peer-lost already 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:

  • Scanner discovers the beacon — ID: 0550aef8749b...
  • Beacon killed → scanner drops it, renders "No beacons nearby yet..."
  • Scanner stays alive — no ECONNRESET, process still running
  • Beacon restarted → scanner rediscovers it — ID: bbddb59bf01f...
  • pnpm run lint — exit 0
  • pnpm test — 4/4 tests, 5/5 asserts

Not addressed here

A restarted beacon comes back with a new id, because getStorageDir() in
backend/index.js suffixes the corestore path with process.pid. The same shop
reads as a different peer after every restart, and storage grows without bound.
Worth a separate change.

@XxHugheadxX
XxHugheadxX merged commit e4d8da6 into main Aug 25, 2026
7 checks passed
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.

1 participant