From 1229c61ba420b280708b39c04cc21f31e43ed3cf Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 12:05:02 +0200 Subject: Make timeout configurable on RPCSubprovider --- packages/subproviders/src/subproviders/rpc_subprovider.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'packages') diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts index 0fb99f87a..5c1c3272c 100644 --- a/packages/subproviders/src/subproviders/rpc_subprovider.ts +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -14,10 +14,12 @@ import { Subprovider } from './subprovider'; */ export class RPCSubprovider extends Subprovider { private _rpcUrl: string; - constructor(rpcUrl: string) { + private _requestTimeoutMs: number; + constructor(rpcUrl: string, requestTimeoutMs: number = 20000) { super(); assert.isString('rpcUrl', rpcUrl); this._rpcUrl = rpcUrl; + this._requestTimeoutMs = requestTimeoutMs; } /** * This method conforms to the web3-provider-engine interface. @@ -35,9 +37,6 @@ export class RPCSubprovider extends Subprovider { 'Content-Type': 'application/json', }); - // Since Ethereum nodes have a proclivity for accepting requests and never - // returning a response, we set this quite low (10 seconds). - const timeoutMs = 10000; let response; try { response = await fetchAsync( @@ -47,7 +46,7 @@ export class RPCSubprovider extends Subprovider { headers, body: JSON.stringify(finalPayload), }, - timeoutMs, + this._requestTimeoutMs, ); } catch (err) { end(new JsonRpcError.InternalError(err)); -- cgit