Yaffle/EventSource
View on GitHub.close() does not abort current event source fetch connections
Open
#120 opened on Oct 23, 2018
help wanted
Description
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
transportwhen 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
})