aws-sdk-js-v3: S3.send sometimes leads to application exit with code 0
Describe the bug
Executing this code…
let s3: S3 = /*...*/;
// Many awaits
await s3.send(
new PutObjectCommand({
Bucket: bucket,
Key: toFile,
Body: data,
CacheControl: cacheControl,
ContentType: contentType ?? undefined,
}),
);
// More awaits
…in the middle of a long chain of awaits sometimes leads to application exit with code 0
.
I believe this may be because of the behavior described here: https://github.com/nodejs/node/issues/22088
Basically, I think, s3.send
somehow drops both its handle to resolve
and reject
, dropping the reference count of scheduled requests in the node runtime to 0, which in turn automatically exits node with code 0
.
This took a long time to figure out and is very confusing when encountering it for the first time.
The reason I think this is what happens, is because when i use the setTimeout
trick, the application stays alive until setTimeout
triggers and then immediately exits with code 0
.
Example of this:
const t = setTimeout(() => console.log("Timeout"), 5000);
await s3.send(
new PutObjectCommand({
Bucket: bucket,
Key: toFile,
Body: data,
CacheControl: cacheControl,
ContentType: contentType ?? undefined,
}),
);
clearTimeout(t);
It seems to happen more often on 4G connections than on WiFi.
Expected Behavior
An actual error to be thrown or printed.
Current Behavior
My node application exits with code 0 even though all code has not been run yet.
Reproduction Steps
Since the error is intermittent, and I have a lot of proprietary code, I can’t give a better example than this:
let s3: S3 = /*...*/;
// Many awaits
await s3.send(
new PutObjectCommand({
Bucket: bucket,
Key: toFile,
Body: data,
CacheControl: cacheControl,
ContentType: contentType ?? undefined,
}),
);
// More awaits
Possible Solution
Hopefully the code in the aws-sdk-js
repository can be fixed.
Additional Information/Context
No response
SDK version used
3.245.0
Environment details (OS name and version, etc.)
macOS 13.0.1 (22A400) node v18.8.0 scripts compiled & run using ts-node
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 46 (15 by maintainers)
I open a PR for this: https://github.com/aws/aws-sdk-js-v3/pull/4492 @trivikr
I’ve opened a PR to fix this https://github.com/aws/aws-sdk-js-v3/pull/4492
Hey, we have probably the same problem.
When I iterate over the DynamoDB table without S3 interaction it just works as expected. Once S3 is involved it just silently fails in the middle of the process. That’s kind of unfortunate. node: v16.18.1
I see from the stack trace that you are executing this with Node 18.0.0. In 18.6.0 a fix for this panic was introduced. So please make sure you use a more recent Node version.
Hi @bes,
I still have no idea what the issue is and why you are the only one experiencing this. I will discuss it again with the team and see some of the more senior peeps can take a deeper look.
Thanks, Ran~