-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: segmentation fault in REPL when trying to use AbortController with node-fetch package, dynamic import and timeouts #44464
Comments
That's probably a duplicate of #38695 |
|
reproduced the same issue with a smaller piece of code
|
After some experimentation, I found the following workaround that works in all general use cases, including loading it as a file from repl. const fetch = (()=>{let m = import("node-fetch");return async (...args)=>await (await m).default(...args);})(); Also, if you are manually importing node-fetch in repl, the following code works as well since repl supports > const fetch = (await import('node-fetch')).default;
...do something with fetch |
Here is some explanation of my workaround: const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args)); Since according to #38695, the problem has to do with premature garbage collection, I thought that if I could manually store aside the result of const fetch = (() => {
let mod = import("node-fetch");
return async (...args) => await (await mod).default(...args);
})(); Shortened form, it would look like this const fetch = (()=>{let m = import("node-fetch");return async (...args)=>await (await m).default(...args);})(); |
Version
v16.17.0
Platform
Darwin ibm-macbook-pro 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64 x86_64 i386 MacBookPro16,1 Darwin
Subsystem
REPL, dynamic import, abort controller, timeout
What steps will reproduce the bug?
You can copy paste the following code into the REPL to trigger the segmentation fault
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior?
The code should not seg fault. It is possible to put the same code in a file (
index.js
) and runnode index.js
and it printstrue
. No seg faults there. Note: you need to put"type": "module"
in the package.json to useawait
at the top level.What do you see instead?
A segmentation fault when the code is run inside the REPL.
Additional information
Node was installed on MacOS Monterey version 12.5.1 using nvm https://github.com/nvm-sh/nvm
Found this segfault while trying out this tutorial on using fetch with a custom timeout https://dmitripavlutin.com/timeout-fetch-request/
The text was updated successfully, but these errors were encountered: