Unhandled Promise rejection "AbortError: The operation was aborted." when using AbortController.abort API to abort an in-progress fetch call
Categories
(Core :: DOM: Networking, defect, P3)
Tracking
()
People
(Reporter: earshinov, Unassigned)
Details
(Keywords: compat, Whiteboard: [necko-triaged])
Attachments
(2 files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
Steps to reproduce:
In my Angular application I am using EventSourcePolyfill1 library to execute a long-running HTTPS request. I am also using Sentry to get notified on errors. I have noticed that a lot of Firefox users receive "AbortError: The operation was aborted." error when eventSource.close
is called. One scenario when I call eventSource.close
is when the user leaves the page (staying within the application) and I don't want to leave the HTTPS request hanging.
Under the hood, EventSourcePolyfill uses fetch and AbortController APIs. I took its code and reproduced the problem on a Stackblitz page: https://stackblitz.com/edit/firefox-fetch-abort-error.
The example uses https://randomuser.me/api/ which does not seem to be open to cross-origin request, so you will need something like Fiddler to reproduce. Or use some other API instead.
You may also look at the screenshot of Firefox DevTools Console logs I attached. There you see the information about unhandledrejection event being triggered on window
. If you look at event.reason.stack
(not displayed on the screenshot), it points to the line where AbortController.abort is called.
Note that I call AbortController.abort inside a Promise.then
callback, and I also handle and explicitly ignore the AbortError in the catch
handler (the "Got AbortError" line on the screenshot). I cannot see where else I can handle the AbortError to prevent uncaughtrejection, because AbortController.abort returns undefined.
The problem does not occur in Chrome.
Firefox version: 69.0.1 (64-bit)
May be related to:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1507193 (Firefox spews AbortError when scrubbing video)
Actual results:
unhandledrejection event with reason "AbortError: The operation was aborted."
Expected results:
No unhandledrejection
Reporter | ||
Comment 1•5 years ago
|
||
Backlink to EventSource library issue: https://github.com/Yaffle/EventSource/issues/130
Comment 2•5 years ago
|
||
Comment 3•5 years ago
|
||
Hi @Evgeny Arshinov, you mean that by pressing on the button "Abort" from the link app you provided, should render the error like in your end? I've cliched this button and no error appears. In case that I'm wrong please add some description along with STR in order what should be executed. Also, I'll add a screenshot with the console app.
Meanwhile, I will add a component, if isn't the right one please fell free to change it.
Regards,
Liviu
Reporter | ||
Comment 4•5 years ago
|
||
Hello!
Sorry for inconvenience. You found the example working because I modified the example to include a call to reader.cancel
as suggested by EventSource library author in https://github.com/Yaffle/EventSource/issues/130#issuecomment-535862539. It seems to resolve the issue.
I commented out the call to reader.cancel
now to make the error reproducible again.
To clarify the issue, now it seems possible to prevent the AbortError. However, it requires an explicit call to reader.cancel(), which is not very intuitive. Also, Chrome does not produce an error even without this call. I think it should be fixed on Firefox's side.
Comment 5•5 years ago
•
|
||
Hi @Evgeny Arshinov, ok, notice that, so we wait for someone from dev's team to decide about it.
Regards,
Liviu
Reporter | ||
Comment 6•5 years ago
|
||
But it isn't resolved. I don't think an explicit call to reader.cancel should be required.
Updated•5 years ago
|
Updated•2 years ago
|
Description
•