Skip to content

Commit

Permalink
fix: set request timeout to 4s by default (#229)
Browse files Browse the repository at this point in the history
* feat: upgrade @types/node

* fix: set request timeout to 4s by default

---------

Co-authored-by: Pierre Milliotte <[email protected]>
  • Loading branch information
pmilliotte and Pierre Milliotte authored Apr 21, 2023
1 parent 017089d commit efc0aef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/aws-lambda": "^8.10.92",
"@types/cookie": "^0.4.1",
"@types/fs-extra": "^9.0.13",
"@types/node": "^17.0.14",
"@types/node": "^18.15.12",
"aws-sdk": "^2.1354.0",
"html-loader": "^3.1.0",
"prettier": "^2.5.1",
Expand Down
9 changes: 8 additions & 1 deletion src/lambda-edge/shared/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { IncomingHttpHeaders } from "http";
import { request, RequestOptions } from "https";
import { Writable, pipeline } from "stream";

const DEFAULT_REQUEST_TIMEOUT = 4000; // 4 seconds

export async function fetch(
uri: string,
data?: Buffer,
Expand All @@ -15,7 +17,12 @@ export async function fetch(
headers: IncomingHttpHeaders;
data: Buffer;
}>((resolve, reject) => {
const req = request(uri, options ?? {}, (res) =>
const requestOptions = {
signal: AbortSignal.timeout(DEFAULT_REQUEST_TIMEOUT),
...(options ?? {}),
};

const req = request(uri, requestOptions, (res) =>
pipeline(
[
res,
Expand Down

0 comments on commit efc0aef

Please sign in to comment.