Skip to content

Commit 99f5f27

Browse files
authored
fix: do not add peers to routing table during RPC handling (#2866)
This can cause a race condition where two peers try to bootstrap to each other, then fail to add the other to the routing table because they wait for the other to respond to a ping first. It also fixes a smaller bug whereby we'd try to add a peer to the routing table after they send us an RPC message but they are a DHT client - they'd not respond to the ping we send before adding them so it's a waste of resources.
1 parent f8da60e commit 99f5f27

File tree

2 files changed

+0
-8
lines changed

2 files changed

+0
-8
lines changed

packages/kad-dht/src/rpc/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ export class RPC {
9595
const { stream, connection } = data
9696
const peerId = connection.remotePeer
9797

98-
try {
99-
await this.routingTable.add(peerId)
100-
} catch (err: any) {
101-
this.log.error(err)
102-
}
103-
10498
const self = this // eslint-disable-line @typescript-eslint/no-this-alias
10599

106100
await pipe(

packages/kad-dht/test/rpc/handlers/ping.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { defaultLogger } from '@libp2p/logger'
44
import { expect } from 'aegir/chai'
5-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
65
import { type Message, MessageType } from '../../../src/message/dht.js'
76
import { PingHandler } from '../../../src/rpc/handlers/ping.js'
87
import { createPeerId } from '../../utils/create-peer-id.js'
@@ -30,7 +29,6 @@ describe('rpc - handlers - Ping', () => {
3029
it('replies with the same message', async () => {
3130
const msg: Message = {
3231
type: T,
33-
key: uint8ArrayFromString('hello'),
3432
closer: [],
3533
providers: []
3634
}

0 commit comments

Comments
 (0)