Skip to content

Commit

Permalink
fix: pass abort signal to stream close
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Sep 30, 2024
1 parent 12bcd86 commit 32c176f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/kad-dht/src/routing-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,21 @@ export class RoutingTable extends TypedEventEmitter<RoutingTableEvents> implemen
}, Message, options)
const response = await pb.read(Message, options)

await pb.unwrap().close()
await pb.unwrap().close(options)

if (response.type !== MessageType.PING) {
throw new InvalidMessageError(`Incorrect message type received, expected PING got ${response.type}`)
}

this.log('old contact %p ping ok', oldContact.peerId)
return true
} catch (err: any) {
if (this.running && this.kb != null) {
if (this.running) {
// only evict peers if we are still running, otherwise we evict
// when dialing is cancelled due to shutdown in progress
this.log.error('could not ping peer %p', oldContact.peerId, err)
this.log.error('could not ping peer %p - %e', oldContact.peerId, err)
this.log('evicting old contact after ping failed %p', oldContact.peerId)
this.kb.remove(oldContact.kadId)
this.kb?.remove(oldContact.kadId)
}

stream?.abort(err)
Expand Down

0 comments on commit 32c176f

Please sign in to comment.