Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit 81cddec

Browse files
authored
Add a 10s timeout to fetching of blocks (#379)
1 parent 4a7f068 commit 81cddec

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/util/ethereum/get-block.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ const getBlock = async blockHash => {
1212
}
1313

1414
const web3Wrapper = web3.getWrapper();
15-
const block = await web3Wrapper.getBlockIfExistsAsync(blockHash);
15+
16+
const timeout = new Promise((resolve, reject) => {
17+
const id = setTimeout(() => {
18+
clearTimeout(id);
19+
reject(new Error(`Fetching block ${blockHash} timed out after 10s`));
20+
}, 10000);
21+
});
22+
23+
const block = await Promise.race([
24+
web3Wrapper.getBlockIfExistsAsync(blockHash),
25+
timeout,
26+
]);
1627

1728
if (block === undefined) {
1829
return null;

0 commit comments

Comments
 (0)