Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix memory leak in recursivePostRetry #207

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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