You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Failed to catch AbortError from undici.request after server returns #3736
The following minimum reproduction log ignore error and hey and then the entire process crashes with process.processTicksAndRejections. It seems that the abort error is leaked instead of being catched.
Reproducible By
constundici=require("undici");(async()=>{console.log(process.version);try{constcontroller=newAbortController();constrequest=async(url,id)=>{constresp=awaitundici.request(url,{signal: controller.signal,});if(id===2){consterror=newError("bail out early");controller.abort(error);throwerror;}console.log(resp.statusCode);// consume bodyawaitresp.body.arrayBuffer();};awaitPromise.any([request("https://cdn.skk.moe",1),request("https://cdn.skk.moe/favicon.ico",2),]);}catch(e){console.log("ignore error");}console.info("hey");})();
Expected Behavior
The above minimum reproduction should log ignore error and hey and the process to exit with 0.
Logs & Screenshots
v22.6.0
ignore error
hey
node:events:498
throw er; // Unhandled 'error' event
^
Error: bail out early
at request (/home/runner/HauntingLikelyPaintprogram/index.js:15:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.any (index 1)
at async /home/runner/HauntingLikelyPaintprogram/index.js:30:5
Emitted 'error' event on BodyReadable instance at:
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Node.js v22.6.0
Environment
Node.js 22.6.0 w/ undici 6.20.1
The error can be reproduced on both Linux and macOS.
Additional context
I am using Promise.any and undici.request to perform requests to multiple mirror URLs to get the fastest response and abort the rest. I also have a local cache and will bail out of all undici.request early if the fastest response matches certain criteria. I want to use try { } catch { } to catch the error and perform some logic.
changed the title [-]Failed to catch AbortError from `undici.request` after header is consumed.[/-][+]Failed to catch AbortError from `undici.request` after server returns[/+]on Oct 15, 2024
Activity
[-]Failed to catch AbortError from `undici.request` after header is consumed.[/-][+]Failed to catch AbortError from `undici.request` after server returns[/+]fix(#3736): leaked error event on response body
fix(#3736): leaked error event on response body (#3740)
fix(nodejs#3736): back-port 183f8e9 to v6.x
fix(#3736): back-port 183f8e9 to v6.x (#3855)