Open AtnesNess opened 4 months ago
What I found is that stream is being destroyed on client connection abort. However, node-fetch stream abortion doesn't destroy the socket. I could see that by checking heap dump, this reference is not being cleared out with garbage collector since the request is not aborted. Ideally this function should be called on stream destroy.
Seems like the issue in node-fetch is outlined here https://github.com/node-fetch/node-fetch/issues/1762.
To conclude this issue is reproducible only when koa and nodeFetchV2 used together
most likely, koa's stream pipelining could use some updates as node has introduced new pipelining features that may handle the aborts better
do you know if this happens with native fetch?
Describe the bug
Node.js version: v18.16.0
OS version: Amazon Linux 2 x86_64
Description: Providing node-fetch response body stream into
ctx.body
leads to TCP memory leak when client aborts data download half way through.Actual behavior
TCP memory keeps increasing with every aborted request and never goes down
Expected behavior
TCP memory to recover after streaming is complete/aborted
Code to reproduce
See https://github.com/AtnesNess/koa-node-fetch-issue
Checklist