Skip to content

Commit f2cd512

Browse files
committed
fix close crash
1 parent 6ed5ab1 commit f2cd512

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/protocol-identify/src/identify.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys'
2-
import { InvalidMessageError, serviceCapabilities } from '@libp2p/interface'
2+
import { InvalidMessageError, StreamStateError, serviceCapabilities } from '@libp2p/interface'
33
import { peerIdFromCID } from '@libp2p/peer-id'
44
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
55
import { isGlobalUnicast, isPrivate, pbStream } from '@libp2p/utils'
@@ -65,7 +65,14 @@ export class Identify extends AbstractIdentify implements Startable, IdentifyInt
6565
}).pb(IdentifyMessage)
6666

6767
const message = await pb.read(options)
68-
await pb.unwrap().unwrap().close(options)
68+
try {
69+
await pb.unwrap().unwrap().close(options)
70+
} catch (err) {
71+
// Remote may have already closed the stream, triggering a StreamStateError
72+
if (!(err instanceof StreamStateError)) {
73+
throw err
74+
}
75+
}
6976

7077
return message
7178
} catch (err: any) {

0 commit comments

Comments
 (0)