Skip to content

Commit

Permalink
Remove debug code and add patch for connection monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed Oct 7, 2024
1 parent 04e8801 commit acbfccf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build": "tsc -p tsconfig.build.json",
"webpack": "webpack --env mode=development && cp ./lib/bundle.cjs ../backend-bundle/bundle.cjs",
"webpack:prod": "webpack --env mode=production && cp ./lib/bundle.cjs ../backend-bundle/bundle.cjs",
"postinstall": "patch -f -p0 < ./patch/electron-fetch.patch || true && patch -f -p0 --forward --binary < ./patch/parse-duration.patch || true && patch -f -p0 --forward --binary < ./patch/parse-duration-esm.patch || true && patch -f -p0 < ./patch/ipfs-pubsub-peer-monitor.patch || true && patch --forward -p0 node_modules/@orbitdb/core/src/oplog/log.js < ./patch/orbitdb-oplog.patch || true && patch --forward -p0 node_modules/@libp2p/kad-dht/dist/src/providers.js < ./patch/libp2p-kaddht-providers.patch || true && patch --forward -p0 node_modules/@helia/block-brokers/node_modules/ipfs-bitswap/dist/src/bitswap.js < ./patch/bitswap.patch || true",
"postinstall": "patch -f -p0 < ./patch/electron-fetch.patch || true && patch -f -p0 --forward --binary < ./patch/parse-duration.patch || true && patch -f -p0 --forward --binary < ./patch/parse-duration-esm.patch || true && patch -f -p0 < ./patch/ipfs-pubsub-peer-monitor.patch || true && patch --forward -p0 node_modules/@orbitdb/core/src/oplog/log.js < ./patch/orbitdb-oplog.patch || true && patch --forward -p0 node_modules/@libp2p/kad-dht/dist/src/providers.js < ./patch/libp2p-kaddht-providers.patch || true && patch --forward -p0 node_modules/@helia/block-brokers/node_modules/ipfs-bitswap/dist/src/bitswap.js < ./patch/bitswap.patch || true && patch --forward -p0 node_modules/libp2p/dist/src/connection-monitor.js < ./patch/libp2p-connection-monitor.patch || true",
"prepare": "npm run webpack",
"version": "git add -A src",
"lint:no-fix": "eslint --ext .jsx,.js,.ts,.tsx ./src/",
Expand Down
49 changes: 49 additions & 0 deletions packages/backend/patch/libp2p-connection-monitor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--- packages/backend/node_modules/libp2p/dist/src/connection-monitor.js 2024-10-07 09:12:19
+++ packages/backend/patch/patch.js 2024-10-07 09:15:58
@@ -7,6 +7,7 @@
const PROTOCOL_NAME = 'ping';
const PROTOCOL_PREFIX = 'ipfs';
const PING_LENGTH = 32;
+const DEFAULT_ABORT_CONN_ON_PING_FAILURE = true
export class ConnectionMonitor {
protocol;
components;
\ No newline at end of file
@@ -15,6 +16,7 @@
pingIntervalMs;
abortController;
timeout;
+ abortConnectionOnPingFailure;
constructor(components, init = {}) {
this.components = components;
this.protocol = `/${init.protocolPrefix ?? PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`;
\ No newline at end of file
@@ -25,6 +27,7 @@
metrics: components.metrics,
metricName: 'libp2p_connection_monitor_ping_time_milliseconds'
});
+ this.abortConnectionOnPingFailure = init.abortConnectionOnPingFailure ?? DEFAULT_ABORT_CONN_ON_PING_FAILURE
}
[Symbol.toStringTag] = '@libp2p/connection-monitor';
[serviceCapabilities] = [
\ No newline at end of file
@@ -70,9 +73,16 @@
conn.rtt = (Date.now() - start) / 2;
}
})
+ // #PATCH: This behavior is pulled from libp2p v2.1.5 (the latest as of writing this) as the original didn't actually honor this flag
.catch(err => {
- this.log.error('error during heartbeat, aborting connection', err);
- conn.abort(err);
+ this.log.error('error during heartbeat', err)
+
+ if (this.abortConnectionOnPingFailure) {
+ this.log.error('aborting connection due to ping failure')
+ conn.abort(err)
+ } else {
+ this.log('connection ping failed, but not aborting due to abortConnectionOnPingFailure flag')
+ }
});
});
}, this.pingIntervalMs);
\ No newline at end of file
19 changes: 0 additions & 19 deletions packages/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,25 +390,6 @@ app.on('ready', async () => {
})
logger.info('Forked backend, PID:', backendProcess.pid)

backendProcess.stdout?.on('data', (chunk: any) => {
logger.info(`STDOUT FROM FORKED PROCESS`, chunk)
})
backendProcess.stderr?.on('data', (chunk: any) => {
logger.info(`STDERR FROM FORKED PROCESS`, chunk)
})

backendProcess.on('spawn', () => {
logger.info('Backend process spawned')
})

backendProcess.on('close', (code, signal) => {
logger.warn('Backend process closed', code, signal)
})

backendProcess.on('disconnect', () => {
logger.info('Backend process disconnected')
})

backendProcess.on('error', e => {
logger.error('Backend process returned error', e)
throw Error(e.message)
Expand Down

0 comments on commit acbfccf

Please sign in to comment.