mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-11 03:59:58 +08:00
A Request's signal follows the signal it was created with through a weak link inside undici: once the Request object is garbage collected, the link is gone and request.signal never aborts (nodejs/undici#3644). The chat route passes req.signal to streamText and holds nothing else from the request, so a GC pause during a stream could leave the model call running after the client stopped or disconnected, with no onAbort accounting. The route now keeps each request in a WeakMap keyed by its response, which Next holds while the body is piped. This is also the cause of the unit test chat-route-abort hanging on CI (three times this week, 60 ms locally): the test's Request is dropped as soon as the route returns, and a GC in that window lost the abort. With a forced GC the test hangs on Node 20 and 24 without this change and passes with it.