OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git commits / 2842013

Fix connectivity test: catch ECONNRESET, detect self-connection
Test was crashing from uncaught ECONNRESET on NoiseSecretStream. Now catches errors on all connections and detects if the peer is the local machine's own pear-git (same topic, wrong server). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
284201338ba3225c0086eeba9bd2f99e149bbe18
by plankatron <fleeky@gmail.com> · 2026-04-07T13:43:26.000Z

Changed files (1) +21 -6

test/p2p-connectivity.js +21 -6
……@@ -26,6 +26,11 @@ const TIMEOUT = 15000
2626let passed = 0
2727let failed = 0
2828
29// Catch uncaught errors from streams — prevent crash
30process.on('uncaughtException', (err) => {
31 console.log(` [uncaught] ${err.code || err.message}`)
32})
33
2934function ok (name) { passed++; console.log(` ✓ ${name}`) }
3035function fail (name, reason) { failed++; console.log(` ✗ ${name}: ${reason}`) }
3136
……@@ -100,21 +105,31 @@ try {
100105 const topic = crypto.hash(Buffer.concat([keyBuf, Buffer.from(REPO, 'utf-8')])).subarray(0, 32)
101106
102107 const swarm3 = new Hyperswarm()
108 swarm3.on('error', () => {}) // prevent uncaught
109
103110 swarm3.join(topic, { server: false, client: true })
104111
105 const conn = await withTimeout(
112 const result = await withTimeout(
106113 new Promise((resolve, reject) => {
107 swarm3.once('connection', (conn, info) => {
108 resolve({ conn, key: info.publicKey.toString('hex').slice(0, 8) })
114 swarm3.on('connection', (conn, info) => {
115 const peerKey = info.publicKey.toString('hex')
116 conn.on('error', () => {}) // prevent uncaught ECONNRESET
117 resolve({ conn, peerKey })
109118 })
110 swarm3.once('error', reject)
111119 }),
112120 TIMEOUT,
113121 'remote connection'
114122 )
115123
116 ok(`Connected to peer ${conn.key}...`)
117 conn.conn.destroy()
124 const shortKey = result.peerKey.slice(0, 12)
125 const isSelf = result.peerKey === swarm3.keyPair.publicKey.toString('hex')
126 if (isSelf) {
127 fail('Remote connection', `connected to SELF (${shortKey}...) — local pear-git serving same topic?`)
128 } else {
129 ok(`Connected to peer ${shortKey}... (not self)`)
130 }
131 result.conn.on('error', () => {})
132 result.conn.destroy()
118133 await swarm3.destroy()
119134} catch (err) {
120135 fail('Remote connection', err.message)