-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove debug code and add patch for connection monitor
- Loading branch information
1 parent
04e8801
commit acbfccf
Showing
3 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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 |
This file contains 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