fix: time out slow reads (#1227)

There are a few places in the codebase where we send/receive data from the network without timeouts/abort controllers which means the user has to wait for the underlying socket to timeout which can take a long time depending on the platform, if at all.

This change ensures we can time out while running identify (both flavours), ping and fetch and adds tests to ensure there are no regressions.
This commit is contained in:
Alex Potsides
2022-05-25 18:15:21 +01:00
committed by GitHub
parent 5934b13cce
commit a1220d22f5
23 changed files with 1039 additions and 442 deletions

View File

@ -18,13 +18,21 @@ describe('Protocol prefix is configurable', () => {
it('protocolPrefix is provided', async () => {
const testProtocol = 'test-protocol'
libp2p = await createLibp2pNode(mergeOptions(baseOptions, {
protocolPrefix: testProtocol
identify: {
protocolPrefix: testProtocol
},
ping: {
protocolPrefix: testProtocol
},
fetch: {
protocolPrefix: testProtocol
}
}))
await libp2p.start()
const protocols = await libp2p.peerStore.protoBook.get(libp2p.peerId)
expect(protocols).to.include.members([
'/libp2p/fetch/0.0.1',
`/${testProtocol}/fetch/0.0.1`,
'/libp2p/circuit/relay/0.1.0',
`/${testProtocol}/id/1.0.0`,
`/${testProtocol}/id/push/1.0.0`,
@ -41,7 +49,8 @@ describe('Protocol prefix is configurable', () => {
'/libp2p/circuit/relay/0.1.0',
'/ipfs/id/1.0.0',
'/ipfs/id/push/1.0.0',
'/ipfs/ping/1.0.0'
'/ipfs/ping/1.0.0',
'/libp2p/fetch/0.0.1'
])
})
})