#Abort fetch on the server

1 messages · Page 1 of 1 (latest)

dusk garnet
#

Is there a way to safely abort a fetch on the server?
I'm following the node-fetch approach but remix is throwing a weird error

[REMIX] /Users/wlad/projects/eatingdots/node_modules/web-streams-polyfill/src/lib/readable-stream.ts:149
[REMIX]       return promiseRejectedWith(new TypeError('Cannot cancel a stream that already has a reader'));
[REMIX]                                  ^
[REMIX] TypeError: Cannot cancel a stream that already has a reader
[REMIX]     at ReadableStream.cancel (/Users/wlad/projects/eatingdots/node_modules/web-streams-polyfill/src/lib/readable-stream.ts:149:34)
[REMIX]     at abort (/Users/wlad/projects/eatingdots/node_modules/@remix-run/web-fetch/src/fetch.js:75:18)
[REMIX]     at AbortSignal.abortAndFinalize (/Users/wlad/projects/eatingdots/node_modules/@remix-run/web-fetch/src/fetch.js:91:4)
[REMIX]     at AbortSignal.[nodejs.internal.kHybridDispatch] (node:internal/event_target:643:20)
[REMIX]     at AbortSignal.dispatchEvent (node:internal/event_target:585:26)
[REMIX]     at abortSignal (node:internal/abort_controller:284:10)
[REMIX]     at AbortController.abort (node:internal/abort_controller:315:5)
[REMIX]     at Timeout.<anonymous> (/Users/wlad/projects/eatingdots/apps/web/app/utils/webhooks.server.ts:211:16)
[REMIX]     at listOnTimeout (node:internal/timers:559:17)
[REMIX]     at processTimers (node:internal/timers:502:7)
warm anchor
#

AFAIK the request.signal you receive on a loader/action is never aborted so you can’t use it

#

So without that there’s no way to abort them

jagged nest
#

I think it actually is now, but only currently when the client disconnects prematurely. But I've only seen that code in the express adapter, haven't checked the other platforms.

dusk garnet
#

So what happens if the fetch response takes longer than the server time limit for executing the loader? Is there no way to handle that?