Skip to content

Commit

Permalink
fix: await result of receiving blocks (#213)
Browse files Browse the repository at this point in the history
`bitswap._receiveMessage` is an async function so you need to `await` on it in order to correctly handle any errors encountered.

I've been seeing `unhandledPromiseRejection` events during test runs, turns out it's when you spin up two nodes, get them to dial each other and transfer data - the tests can shut the nodes down and clean up their repos before they've finished processing incoming blocks leading to `Error: ENOENT: no such file or directory` errors as the repos are deleted out from under the blockstore.

`await`ing on the result of `bitswap._receiveMessage` fixes this by handling the error.
  • Loading branch information
achingbrain authored Feb 10, 2020
1 parent 871e6b3 commit dae48dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Network {
for await (const data of source) {
try {
const message = await Message.deserialize(data.slice())
this.bitswap._receiveMessage(connection.remotePeer, message)
await this.bitswap._receiveMessage(connection.remotePeer, message)
} catch (err) {
this.bitswap._receiveError(err)
break
Expand Down

0 comments on commit dae48dd

Please sign in to comment.