Skip to content

Commit

Permalink
fix: rpc timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dulguun0225 committed Aug 21, 2023
1 parent 90eae38 commit 125eef5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/api-utils/src/messageBroker.ts
Expand Up @@ -18,6 +18,19 @@ const httpAgentOptions = {
const keepaliveAgent = new Agent(httpAgentOptions);
const secureKeepaliveAgent = new Agent.HttpsAgent(httpAgentOptions);

function getHttpAgent(protocol: string, args: any): Agent | Agent.HttpsAgent {
if (args.timeout && Number(args.timeout)) {
const options = { ... httpAgentOptions, timeout: Number(args.timeout)};
if(protocol === "http:") {
return new Agent(options);
} else {
return new Agent.HttpsAgent(options);
}
} else {
return protocol === "http:" ? keepaliveAgent : secureKeepaliveAgent;
}
}

const showInfoDebug = () => {
if ((process.env.DEBUG || '').includes('error')) {
return false;
Expand Down Expand Up @@ -157,10 +170,7 @@ export const sendRPCMessage = async (
'Content-Type': 'application/json'
},
body: JSON.stringify(args),
agent: parsedURL =>
parsedURL.protocol === 'http:'
? keepaliveAgent
: secureKeepaliveAgent,
agent: parsedURL => getHttpAgent(parsedURL.protocol, args),
compress: false
});

Expand Down

0 comments on commit 125eef5

Please sign in to comment.