Closed
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
When an error occurs in the request, there is no waiting time for the cotinue event,
If the socketTimeout set is relatively long, Lambda will timeout
SDK version number
@aws-sdk/node-http-handler": "3.344.0"
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v18.16.0
Reproduction Steps
set socketTimeout of S3Client to 15 minute
s3 = new S3Client({
apiVersion: "2006-03-01",
requestHandler: new NodeHttpHandler({
socketTimeout: 15 * 60 * 1000
}),
});
Usually, uploading files only takes one minute, but sometimes Lambda times out
const parallelUploadS3 = new Upload({
client: s3,
params: {
Bucket: bucket,
Key: key,
Body: body
}
});
await parallelUploadS3.done();
Observed Behavior
Lambda timeout
Expected Behavior
The file can be uploaded successfully
Possible Solution
Possible reason: When an error occurs in the request, there is no waiting time for the cotinue event, so the configured 15 minute timeout will be applied
packages/node-http-handler/src/write-request-body.ts
export async function writeRequestBody(
httpRequest: ClientRequest | ClientHttp2Stream,
request: HttpRequest,
maxContinueTimeoutMs = MIN_WAIT_TIME
): Promise<void> {
const headers = request.headers ?? {};
const expect = headers["Expect"] || headers["expect"];
let timeoutId = -1;
let hasError = false;
if (expect === "100-continue") {
await Promise.race<void>([
new Promise((resolve) => {
timeoutId = Number(setTimeout(resolve, Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
}),
new Promise((resolve) => {
httpRequest.on("continue", () => {
clearTimeout(timeoutId);
resolve();
});
httpRequest.on("error", () => {
hasError = true;
clearTimeout(timeoutId);
resolve();
});
}),
]);
}
if(!hasError) {
writeBody(httpRequest, request.body);
}
}
Additional Information/Context
v3.329.0 is work fine.