Skip to content

Commit

Permalink
fix: timeout calculation for httpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeneos committed Sep 2, 2024
1 parent eb77691 commit cb6449c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/salesforce/src/connection/httpTransport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
import * as http from 'http';
import * as https from 'https';
import * as zlib from 'zlib';
Expand Down Expand Up @@ -186,14 +187,14 @@ export class HttpTransport implements Transport {
* @param info Request information
* @param options deprecated
* @returns Promise with the response
*/
public httpRequest(info: HttpRequestInfo, options?: object): Promise<HttpResponse> {
*/
public httpRequest(info: HttpRequestInfo): Promise<HttpResponse>;
public httpRequest(info: HttpRequestInfo, options?: object): Promise<HttpResponse>;
public httpRequest(info: HttpRequestInfo): Promise<HttpResponse> {
const url = this.parseUrl(info.url);
const request = this.prepareRequest(info);

this.logger.debug('%s %s', info.method, url.pathname);

const timer = new Timer();
const request = this.prepareRequest(info);
const requestPromise = new DeferredPromise<HttpResponse>();

// Handle error and response
Expand Down Expand Up @@ -221,7 +222,7 @@ export class HttpTransport implements Transport {

request.once('timeout', () => {
request.destroy(new CustomError(
`Client timeout (${info.timeout}ms) expired when requesting ${url.pathname} (${request.method}) after ${timer.elapsed}ms`,
`Client timeout (${request.socket?.timeout + 'ms' ?? 'default'}) expired when requesting ${url.pathname} (${request.method}) after ${timer.elapsed}ms`,
{ code: 'CLIENT_TIMEDOUT' }
));
});
Expand Down Expand Up @@ -265,7 +266,8 @@ export class HttpTransport implements Transport {
port: url.port,
headers: info.headers,
protocol: url.protocol,
method: info.method
method: info.method,
timeout: httpAgent.options.timeout,
});

if (info.timeout) {
Expand Down

0 comments on commit cb6449c

Please sign in to comment.