Skip to content

Commit 12f1bb0

Browse files
authoredJan 21, 2022
fix: catch errors during identify (#1138)
Sometimes identify can be started while we are shutting down (for example) - we should just log these errors.
1 parent a4bba35 commit 12f1bb0

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed
 

‎src/identify/index.js

+21-17
Original file line numberDiff line numberDiff line change
@@ -267,25 +267,25 @@ class IdentifyService {
267267
* @returns {Promise<void>}
268268
*/
269269
async _handleIdentify ({ connection, stream }) {
270-
let publicKey = new Uint8Array(0)
271-
if (this.peerId.pubKey) {
272-
publicKey = this.peerId.pubKey.bytes
273-
}
270+
try {
271+
let publicKey = new Uint8Array(0)
272+
if (this.peerId.pubKey) {
273+
publicKey = this.peerId.pubKey.bytes
274+
}
274275

275-
const signedPeerRecord = await this.peerStore.addressBook.getRawEnvelope(this.peerId)
276-
const protocols = await this.peerStore.protoBook.get(this.peerId)
276+
const signedPeerRecord = await this.peerStore.addressBook.getRawEnvelope(this.peerId)
277+
const protocols = await this.peerStore.protoBook.get(this.peerId)
277278

278-
const message = Message.Identify.encode({
279-
protocolVersion: this._host.protocolVersion,
280-
agentVersion: this._host.agentVersion,
281-
publicKey,
282-
listenAddrs: this._libp2p.multiaddrs.map((ma) => ma.bytes),
283-
signedPeerRecord,
284-
observedAddr: connection.remoteAddr.bytes,
285-
protocols
286-
}).finish()
279+
const message = Message.Identify.encode({
280+
protocolVersion: this._host.protocolVersion,
281+
agentVersion: this._host.agentVersion,
282+
publicKey,
283+
listenAddrs: this._libp2p.multiaddrs.map((ma) => ma.bytes),
284+
signedPeerRecord,
285+
observedAddr: connection.remoteAddr.bytes,
286+
protocols
287+
}).finish()
287288

288-
try {
289289
await pipe(
290290
[message],
291291
lp.encode(),
@@ -343,7 +343,11 @@ class IdentifyService {
343343
}
344344

345345
// Update the protocols
346-
await this.peerStore.protoBook.set(id, message.protocols)
346+
try {
347+
await this.peerStore.protoBook.set(id, message.protocols)
348+
} catch (/** @type {any} */ err) {
349+
log.error('received invalid protocols', err)
350+
}
347351
}
348352

349353
/**

0 commit comments

Comments
 (0)