stream: fix some memory leaks in internal stream handling (#581)

This commit is contained in:
jj
2024-06-22 12:57:30 +02:00
committed by GitHub
parent 21d5b4b8d4
commit ef97ff06af
2 changed files with 24 additions and 10 deletions

View File

@@ -78,16 +78,25 @@ export function createInternalStream(url, obj = {}) {
}
const streamID = nanoid();
const controller = new AbortController();
internalStreamCache[streamID] = {
url,
service: obj.service,
headers: obj.headers,
controller: new AbortController(),
controller,
dispatcher
};
let streamLink = new URL('/api/istream', `http://127.0.0.1:${env.apiPort}`);
streamLink.searchParams.set('id', streamID);
const cleanup = () => {
destroyInternalStream(streamLink);
controller.signal.removeEventListener('abort', cleanup);
}
controller.signal.addEventListener('abort', cleanup);
return streamLink.toString();
}