Skip to content

Commit

Permalink
Fixes http timeout issues in node 12.
Browse files Browse the repository at this point in the history
  • Loading branch information
bojeil-google authored and hiranya911 committed Jul 8, 2020
1 parent 258fcfc commit dc523db
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,15 @@ class AsyncHttpCall {
});

const timeout: number | undefined = this.config.timeout;
const timeoutCallback = () => {
req.abort();
this.rejectWithError(`timeout of ${timeout}ms exceeded`, 'ETIMEDOUT', req);
};
if (timeout) {
// Listen to timeouts and throw an error.
req.setTimeout(timeout, () => {
req.abort();
this.rejectWithError(`timeout of ${timeout}ms exceeded`, 'ETIMEDOUT', req);
req.setTimeout(timeout, timeoutCallback);
req.on('socket', (socket) => {
socket.setTimeout(timeout, timeoutCallback);
});
}

Expand Down

0 comments on commit dc523db

Please sign in to comment.