You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: don't memory-leak promises passed to waitUntil (#75041)
### Overview
`next start` stores pending promises passed to `waitUntil` so that we
can await them before a (graceful) server shutdown and avoid
interrupting work that's still running.
The problem here was that this set lives a long time (the whole lifetime
of the server), but we weren't removing resolved promises from this set,
so we'd end up holding onto them forever and leaking memory.
This bug would be triggered by any code using `waitUntil` in `next
start` (notably, a recent change:
#74164)
### Details
The bug here is that `AwaiterMulti` would hold onto resolved promises
indefinitely. `AwaiterMulti` ends up being used by
`NextNodeServer.getInternalWaitUntil`, which is what provides
`waitUntil` in `next start`.
The code was already attempting to clean up promises to avoid leaks. But
the problem was that we weren't adding `promise` to `this.promises`, we
were adding `promise.then(...)` which is a completely different object.
So the `this.promises.delete(promise)` that `cleanup` did was
effectively doing nothing, and `this.promises` would keep growing.
0 commit comments