mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 12:26:19 +00:00
Cleanup dead connections in peer heartbeat checker (#394)
* Cleanup dead connections in peer heartbeat checker * Remove yamux muxer
This commit is contained in:
parent
6731a640a2
commit
aa10a2dc05
@ -31,7 +31,6 @@
|
||||
"@cerc-io/libp2p": "0.42.2-laconic-0.1.3",
|
||||
"@cerc-io/prometheus-metrics": "1.1.4",
|
||||
"@chainsafe/libp2p-noise": "^11.0.0",
|
||||
"@chainsafe/libp2p-yamux": "^4.0.2",
|
||||
"@libp2p/floodsub": "^6.0.0",
|
||||
"@libp2p/mplex": "^7.1.1",
|
||||
"@libp2p/peer-id-factory": "^2.0.0",
|
||||
|
@ -11,6 +11,8 @@ import { getPseudonymForPeerId } from './utils/index.js';
|
||||
|
||||
const log = debug('laconic:peer-heartbeat-checker');
|
||||
|
||||
export const MUXER_CLOSED_ERR = 'Muxer already closed';
|
||||
|
||||
interface PeerData {
|
||||
intervalId: NodeJS.Timer;
|
||||
latencyValues: Array<number>;
|
||||
@ -141,10 +143,22 @@ export class PeerHearbeatChecker {
|
||||
// On error i.e. no pong
|
||||
log(err?.message);
|
||||
|
||||
// Retry after a delay of pingTimeout in case ping fails immediately
|
||||
const conns = this._node.getConnections(peerId);
|
||||
|
||||
// If there are multiple connections to the peer and ping was being attempted on a dead connection,
|
||||
// forcefully close/cleanup that connection (always the first one)
|
||||
if (conns.length > 1 && err?.message.includes(MUXER_CLOSED_ERR)) {
|
||||
log(`Closing a dead connection ${conns[0].id} to peer ${peerId.toString()}`);
|
||||
await conns[0].close();
|
||||
|
||||
// Don't count this attempt and do the next ping attempt immediately
|
||||
i--;
|
||||
} else {
|
||||
// Retry after a delay of pingTimeout in case ping fails
|
||||
await retryDelayPromise;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pingSuccess) {
|
||||
return;
|
||||
|
@ -16,7 +16,6 @@ import { createLibp2p, Libp2p, Libp2pInit } from '@cerc-io/libp2p';
|
||||
import { webSockets } from '@libp2p/websockets';
|
||||
import { noise } from '@chainsafe/libp2p-noise';
|
||||
import { mplex } from '@libp2p/mplex';
|
||||
import { yamux } from '@chainsafe/libp2p-yamux';
|
||||
import type { Stream as P2PStream, Connection } from '@libp2p/interface-connection';
|
||||
import type { PeerInfo } from '@libp2p/interface-peer-info';
|
||||
import type { Message } from '@libp2p/interface-pubsub';
|
||||
@ -158,7 +157,7 @@ export class Peer {
|
||||
listen: initOptions.listenMultiaddrs ?? []
|
||||
},
|
||||
connectionEncryption: [noise()],
|
||||
streamMuxers: [mplex(), yamux()],
|
||||
streamMuxers: [mplex()],
|
||||
pubsub: floodsub({ globalSignaturePolicy: PUBSUB_SIGNATURE_POLICY }),
|
||||
peerDiscovery: [
|
||||
// Use pubsub based discovery; relay server acts as a peer discovery source
|
||||
|
112
yarn.lock
112
yarn.lock
@ -433,28 +433,6 @@
|
||||
uint8arraylist "^2.3.2"
|
||||
uint8arrays "^4.0.2"
|
||||
|
||||
"@chainsafe/libp2p-yamux@^4.0.2":
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@chainsafe/libp2p-yamux/-/libp2p-yamux-4.0.2.tgz#2e970da83cda5551c834fb786963007a71e772f1"
|
||||
integrity sha512-p0m/4ab4JLaIQqUtxvm8bSqdt9sb0uXX8PFj1CQM1eJLeV1LxzzygaSOeLxN/5ckHCuK7q/9eb9xybvl6vz/JA==
|
||||
dependencies:
|
||||
"@libp2p/interface-connection" "^5.1.0"
|
||||
"@libp2p/interface-stream-muxer" "^4.1.2"
|
||||
"@libp2p/interfaces" "^3.3.2"
|
||||
"@libp2p/logger" "^2.0.7"
|
||||
abortable-iterator "^5.0.1"
|
||||
any-signal "^4.1.1"
|
||||
it-pipe "^3.0.1"
|
||||
it-pushable "^3.1.3"
|
||||
uint8arraylist "^2.4.3"
|
||||
|
||||
"@chainsafe/netmask@^2.0.0":
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@chainsafe/netmask/-/netmask-2.0.0.tgz#0d4a75f47919f65011da4327a3845c9661f1038a"
|
||||
integrity sha512-I3Z+6SWUoaljh3TBzCnCxjlUyN8tA+NAk5L6m9IxvCf1BENQTePzPMis97CoN/iMW1St3WN+AWCCRp+TTBRiDg==
|
||||
dependencies:
|
||||
"@chainsafe/is-ip" "^2.0.1"
|
||||
|
||||
"@cspotcode/source-map-support@^0.8.0":
|
||||
version "0.8.1"
|
||||
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
|
||||
@ -2405,17 +2383,6 @@
|
||||
it-stream-types "^1.0.4"
|
||||
uint8arraylist "^2.1.2"
|
||||
|
||||
"@libp2p/interface-connection@^5.0.0", "@libp2p/interface-connection@^5.1.0":
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interface-connection/-/interface-connection-5.1.1.tgz#da0572c76da43629d52b8bec6cd092143fae421d"
|
||||
integrity sha512-ytknMbuuNW72LYMmTP7wFGP5ZTaUSGBCmV9f+uQ55XPcFHtKXLtKWVU/HE8IqPmwtyU8AO7veGoJ/qStMHNRVA==
|
||||
dependencies:
|
||||
"@libp2p/interface-peer-id" "^2.0.0"
|
||||
"@libp2p/interfaces" "^3.0.0"
|
||||
"@multiformats/multiaddr" "^12.0.0"
|
||||
it-stream-types "^2.0.1"
|
||||
uint8arraylist "^2.4.3"
|
||||
|
||||
"@libp2p/interface-content-routing@^2.0.0":
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interface-content-routing/-/interface-content-routing-2.0.1.tgz#e050dc42adc3e9b4f1666eafa889c88f892ba1c4"
|
||||
@ -2497,13 +2464,6 @@
|
||||
dependencies:
|
||||
multiformats "^11.0.0"
|
||||
|
||||
"@libp2p/interface-peer-id@^2.0.2":
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interface-peer-id/-/interface-peer-id-2.0.2.tgz#6302e70b6fc17c451bc3daa11447d059357bcc32"
|
||||
integrity sha512-9pZp9zhTDoVwzRmp0Wtxw0Yfa//Yc0GqBCJi3EznBDE6HGIAVvppR91wSh2knt/0eYg0AQj7Y35VSesUTzMCUg==
|
||||
dependencies:
|
||||
multiformats "^11.0.0"
|
||||
|
||||
"@libp2p/interface-peer-info@^1.0.0", "@libp2p/interface-peer-info@^1.0.2":
|
||||
version "1.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interface-peer-info/-/interface-peer-info-1.0.9.tgz#4b1ff859b7861f4387a69711850b3ac31eaedc56"
|
||||
@ -2595,20 +2555,6 @@
|
||||
"@libp2p/interfaces" "^3.0.0"
|
||||
it-stream-types "^1.0.4"
|
||||
|
||||
"@libp2p/interface-stream-muxer@^4.1.2":
|
||||
version "4.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interface-stream-muxer/-/interface-stream-muxer-4.1.2.tgz#f0a5edb906ec784d991b9421a024f0f21ebdaab4"
|
||||
integrity sha512-dQJcn67UaAa8YQFRJDhbo4uT453z/2lCzD/ZwTk1YOqJxATXbXgVcB8dXDQFEUiUX3ZjVQ1IBu+NlQd+IZ++zw==
|
||||
dependencies:
|
||||
"@libp2p/interface-connection" "^5.0.0"
|
||||
"@libp2p/interfaces" "^3.0.0"
|
||||
"@libp2p/logger" "^2.0.7"
|
||||
abortable-iterator "^5.0.1"
|
||||
any-signal "^4.1.1"
|
||||
it-pushable "^3.1.3"
|
||||
it-stream-types "^2.0.1"
|
||||
uint8arraylist "^2.4.3"
|
||||
|
||||
"@libp2p/interface-transport@^2.0.0", "@libp2p/interface-transport@^2.1.0":
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interface-transport/-/interface-transport-2.1.1.tgz#e463f30b272494c177d3a0bd494545616fd7b624"
|
||||
@ -2625,11 +2571,6 @@
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interfaces/-/interfaces-3.3.1.tgz#519c77c030b10d776250bbebf65990af53ccb2ee"
|
||||
integrity sha512-3N+goQt74SmaVOjwpwMPKLNgh1uDQGw8GD12c40Kc86WOq0qvpm3NfACW+H8Su2X6KmWjCSMzk9JWs9+8FtUfg==
|
||||
|
||||
"@libp2p/interfaces@^3.3.2":
|
||||
version "3.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/interfaces/-/interfaces-3.3.2.tgz#5d8079be845b0960939b5b18880e785a4714465a"
|
||||
integrity sha512-p/M7plbrxLzuQchvNwww1Was7ZeGE2NaOFulMaZBYIihU8z3fhaV+a033OqnC/0NTX/yhfdNOG7znhYq3XoR/g==
|
||||
|
||||
"@libp2p/keychain@^1.0.0":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/keychain/-/keychain-1.0.1.tgz#f34d611ece45bd871f597bd14ce61e60459c6d5d"
|
||||
@ -2666,17 +2607,6 @@
|
||||
interface-datastore "^7.0.0"
|
||||
multiformats "^11.0.0"
|
||||
|
||||
"@libp2p/logger@^2.0.7":
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/logger/-/logger-2.1.1.tgz#e12e6c320ea64252af954bcec996895098d1cd36"
|
||||
integrity sha512-2UbzDPctg3cPupF6jrv6abQnAUTrbLybNOj0rmmrdGm1cN2HJ1o/hBu0sXuq4KF9P1h/eVRn1HIRbVIEKnEJrA==
|
||||
dependencies:
|
||||
"@libp2p/interface-peer-id" "^2.0.2"
|
||||
"@multiformats/multiaddr" "^12.1.3"
|
||||
debug "^4.3.4"
|
||||
interface-datastore "^8.2.0"
|
||||
multiformats "^11.0.2"
|
||||
|
||||
"@libp2p/mplex@^7.1.1":
|
||||
version "7.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@libp2p/mplex/-/mplex-7.1.2.tgz#7bc4be3ff28848b51e07ce06dbd9737c108c7a13"
|
||||
@ -2983,19 +2913,6 @@
|
||||
uint8arrays "^4.0.2"
|
||||
varint "^6.0.0"
|
||||
|
||||
"@multiformats/multiaddr@^12.1.3":
|
||||
version "12.1.3"
|
||||
resolved "https://registry.yarnpkg.com/@multiformats/multiaddr/-/multiaddr-12.1.3.tgz#aff5aa61ec19c5320f0b756e88c3bbaac8d1c7af"
|
||||
integrity sha512-rNcS3njkkSwuGF4x58L47jGH5kBXBfJPNsWnrt0gujhNYn6ReDt1je7vEU5/ddrVj0TStgxw+Hm+TkYDK0b60w==
|
||||
dependencies:
|
||||
"@chainsafe/is-ip" "^2.0.1"
|
||||
"@chainsafe/netmask" "^2.0.0"
|
||||
"@libp2p/interfaces" "^3.3.1"
|
||||
dns-over-http-resolver "^2.1.0"
|
||||
multiformats "^11.0.0"
|
||||
uint8arrays "^4.0.2"
|
||||
varint "^6.0.0"
|
||||
|
||||
"@noble/ed25519@^1.6.0":
|
||||
version "1.7.3"
|
||||
resolved "https://registry.yarnpkg.com/@noble/ed25519/-/ed25519-1.7.3.tgz#57e1677bf6885354b466c38e2b620c62f45a7123"
|
||||
@ -4378,14 +4295,6 @@ abortable-iterator@^4.0.2:
|
||||
get-iterator "^2.0.0"
|
||||
it-stream-types "^1.0.3"
|
||||
|
||||
abortable-iterator@^5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/abortable-iterator/-/abortable-iterator-5.0.1.tgz#5d93eba6fa8287a973a9ea090c64ca08b3777780"
|
||||
integrity sha512-hlZ5Z8UwqrKsJcelVPEqDduZowJPBQJ9ZhBC2FXpja3lXy8X6MoI5uMzIgmrA8+3jcVnp8TF/tx+IBBqYJNUrg==
|
||||
dependencies:
|
||||
get-iterator "^2.0.0"
|
||||
it-stream-types "^2.0.1"
|
||||
|
||||
abstract-level@^1.0.0, abstract-level@^1.0.2, abstract-level@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/abstract-level/-/abstract-level-1.0.3.tgz#78a67d3d84da55ee15201486ab44c09560070741"
|
||||
@ -4595,11 +4504,6 @@ any-signal@^3.0.0:
|
||||
resolved "https://registry.yarnpkg.com/any-signal/-/any-signal-3.0.1.tgz#49cae34368187a3472e31de28fb5cb1430caa9a6"
|
||||
integrity sha512-xgZgJtKEa9YmDqXodIgl7Fl1C8yNXr8w6gXjqK3LW4GcEiYT+6AQfJSE/8SPsEpLLmcvbv8YU+qet94UewHxqg==
|
||||
|
||||
any-signal@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/any-signal/-/any-signal-4.1.1.tgz#928416c355c66899e6b2a91cad4488f0324bae03"
|
||||
integrity sha512-iADenERppdC+A2YKbOXXB2WUeABLaM6qnpZ70kZbPZ1cZMMJ7eF+3CaYm+/PhBizgkzlvssC7QuHS30oOiQYWA==
|
||||
|
||||
anymatch@~3.1.1, anymatch@~3.1.2:
|
||||
version "3.1.3"
|
||||
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e"
|
||||
@ -9838,15 +9742,6 @@ interface-datastore@^8.0.0:
|
||||
nanoid "^4.0.0"
|
||||
uint8arrays "^4.0.2"
|
||||
|
||||
interface-datastore@^8.2.0:
|
||||
version "8.2.3"
|
||||
resolved "https://registry.yarnpkg.com/interface-datastore/-/interface-datastore-8.2.3.tgz#491f6e90da963dbbb23d44c97aaae38959a797de"
|
||||
integrity sha512-5U6BfK7cR4oSngm4pqYZBBAX7tpLI4YCOa3Ifz/EJEaEV2mmlloH5qP8ADWCVFk6vP1MPT925JJkt3kFIi7iWQ==
|
||||
dependencies:
|
||||
interface-store "^5.0.0"
|
||||
nanoid "^4.0.0"
|
||||
uint8arrays "^4.0.2"
|
||||
|
||||
interface-store@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.npmjs.org/interface-store/-/interface-store-2.0.1.tgz"
|
||||
@ -10645,11 +10540,6 @@ it-pushable@^3.0.0, it-pushable@^3.1.0, it-pushable@^3.1.2:
|
||||
resolved "https://registry.yarnpkg.com/it-pushable/-/it-pushable-3.1.2.tgz#6f2420fb192f637613c561720945a36b6d9160ae"
|
||||
integrity sha512-zU9FbeoGT0f+yobwm8agol2OTMXbq4ZSWLEi7hug6TEZx4qVhGhGyp31cayH04aBYsIoO2Nr5kgMjH/oWj2BJQ==
|
||||
|
||||
it-pushable@^3.1.3:
|
||||
version "3.1.3"
|
||||
resolved "https://registry.yarnpkg.com/it-pushable/-/it-pushable-3.1.3.tgz#b6f4a1e0236502f12b5661b40468b629799baf0e"
|
||||
integrity sha512-f50iQ85HISS6DaWCyrqf9QJ6G/kQtKIMf9xZkgZgyOvxEQDfn8OfYcLXXquCqgoLboxQtAW1ZFZyFIAsLHDtJw==
|
||||
|
||||
it-reader@^6.0.1:
|
||||
version "6.0.2"
|
||||
resolved "https://registry.yarnpkg.com/it-reader/-/it-reader-6.0.2.tgz#2177afca42f0b41c6acc582cc6fc6869ae8d4dd4"
|
||||
@ -12197,7 +12087,7 @@ multiformats@^10.0.0:
|
||||
resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-10.0.3.tgz#d4147d01f9a31271c6fb5d24adf9b01f9e656bba"
|
||||
integrity sha512-K2yGSmstS/oEmYiEIieHb53jJCaqp4ERPDQAYrm5sV3UUrVDZeshJQCK6GHAKyIGufU1vAcbS0PdAAZmC7Tzcw==
|
||||
|
||||
multiformats@^11.0.0, multiformats@^11.0.2:
|
||||
multiformats@^11.0.0:
|
||||
version "11.0.2"
|
||||
resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-11.0.2.tgz#b14735efc42cd8581e73895e66bebb9752151b60"
|
||||
integrity sha512-b5mYMkOkARIuVZCpvijFj9a6m5wMVLC7cf/jIPd5D/ARDOfLC5+IFkbgDXQgcU2goIsTD/O9NY4DI/Mt4OGvlg==
|
||||
|
Loading…
Reference in New Issue
Block a user