Skip to content

Commit

Permalink
prevent disconnect on snap on status timeout as no status handshake o…
Browse files Browse the repository at this point in the history
…n snap
  • Loading branch information
g11tech committed May 24, 2022
1 parent 0bff75f commit a0a19a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/devp2p/src/protocol/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ETH extends Protocol {

_handleStatus(): void {
if (this._status === null || this._peerStatus === null) return
clearTimeout(this._statusTimeoutId)
clearTimeout(this._statusTimeoutId!)

assertEq(
this._status[0],
Expand Down
2 changes: 1 addition & 1 deletion packages/devp2p/src/protocol/les.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class LES extends Protocol {

_handleStatus() {
if (this._status === null || this._peerStatus === null) return
clearTimeout(this._statusTimeoutId)
clearTimeout(this._statusTimeoutId!)
assertEq(
this._status['protocolVersion'],
this._peerStatus['protocolVersion'],
Expand Down
11 changes: 7 additions & 4 deletions packages/devp2p/src/protocol/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Protocol extends EventEmitter {
_version: number
_peer: Peer
_send: SendMethod
_statusTimeoutId: NodeJS.Timeout
_statusTimeoutId?: NodeJS.Timeout
_messageCodes: MessageCodes
_debug: Debugger
_verbose: boolean
Expand All @@ -45,9 +45,12 @@ export class Protocol extends EventEmitter {
this._send = send
this._version = version
this._messageCodes = messageCodes
this._statusTimeoutId = setTimeout(() => {
this._peer.disconnect(DISCONNECT_REASONS.TIMEOUT)
}, ms('5s'))
this._statusTimeoutId =
protocol !== EthProtocol.SNAP
? setTimeout(() => {
this._peer.disconnect(DISCONNECT_REASONS.TIMEOUT)
}, ms('5s'))
: undefined

this._debug = devp2pDebug.extend(protocol)
this._verbose = createDebugLogger('verbose').enabled
Expand Down

0 comments on commit a0a19a9

Please sign in to comment.