Skip to content

Commit

Permalink
🐛 Fix memory leak in recursivePostRetry (#207)
Browse files Browse the repository at this point in the history
* Fix memory leak in `recursivePostRetry`

* remove size limit from deps
  • Loading branch information
dawsbot committed Apr 6, 2023
1 parent ae50d17 commit 0f4df8e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
25 changes: 20 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
],
"scripts": {
"size": "size-limit",
"size": "npx size-limit",
"test": "npm-run-all --parallel jest compile lint",
"test:all-node-versions": "npx trevor",
"lint": "eslint --cache --fix .",
Expand Down Expand Up @@ -90,7 +90,6 @@
"perf_hooks": "^0.0.1",
"prettier": "^2.8.4",
"prettier-plugin-organize-imports": "^2.3.4",
"size-limit": "^7.0.8",
"ts-jest": "^27.1.4",
"ts-node": "^10.2.1",
"typedoc": "^0.22.15",
Expand Down
24 changes: 17 additions & 7 deletions src/providers/FallthroughProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import { logger } from '../logger/logger';
import { BaseProvider } from './BaseProvider';

// https://advancedweb.hu/how-to-add-timeout-to-a-promise-in-javascript/
const promiseTimeout = (prom: Promise<any>, time: number) =>
Promise.race([
prom,
new Promise((_r, reject) =>
setTimeout(() => reject('Promise timed out'), time),
),
]);
const promiseTimeout = <T>(prom: Promise<T>, time: number): Promise<T> =>
new Promise<T>((resolve, reject) => {
const timeout = setTimeout(
() => reject(new Error('Promise timed out')),
time,
);

prom
.then((result) => {
clearTimeout(timeout);
resolve(result);
})
.catch((error) => {
clearTimeout(timeout);
reject(error);
});
});

export interface ConstructorOptions {
timeoutDuration?: number;
Expand Down
7 changes: 0 additions & 7 deletions src/providers/test/json-rpc-provider/get-block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ describe('provider.getBlock', () => {
]);
testBlockEquality(eeRandomBlock, ethersRandomBlock);
});
it(`should match web3.js -- random block as decimal integer & transactions. (block #${blockNumber})`, async () => {
const [eeRandomBlock, web3RandomBlock] = await Promise.all([
essentialEthProvider.getBlock(blockNumber, true),
web3Provider.eth.getBlock(blockNumber, true),
]);
testBlockEquality(eeRandomBlock, web3RandomBlock);
});

const blockHash =
'0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970'; // Hash corresponds to block on RSK Mainnet
Expand Down

0 comments on commit 0f4df8e

Please sign in to comment.