EventSource: .close() does not abort current event source fetch connections
Fetch supports abort, if it is not provided or called it leaves long leaving TCP connections open. Abort package : https://www.npmjs.com/package/abortcontroller-polyfill
Example code/changes that could make this work:
-
Create a controller as described in https://www.npmjs.com/package/abortcontroller-polyfill
-
Add the abort signal to the call of
transport
transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders, controller.signal);
- Store the controller in order to be able to access it in
close
es.controller = controller;
- Update close
EventSourcePolyfill.prototype.close = function () {
this.controller.abort();
this._close();
};
- Update the definition of
transport
when the browser supports fetch
FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers, signal) {
// cache: "no-store"
// https://bugs.chromium.org/p/chromium/issues/detail?id=453190
var textDecoder = new TextDecoder();
fetch(url, {
headers: headers,
credentials: withCredentials ? "include" : "same-origin",
signal: signal
})
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 20 (11 by maintainers)
any updates on this?
Thanks a lot! I will be able to test it next week
https://github.com/Yaffle/EventSource/commit/fd5408ef717b4679c186c80644dd46226176f03d - I have tried to use the suggested changes.
try to use the
Transport
option:I see no solutions with
Fetch API
.