mirror of
https://github.com/nestjs/nest.git
synced 2026-10-28 09:45:43 +08:00
The built-in body parsers call next() from the "end" event of the request, which Node.js emits in the async context of the socket. For every request with a body, the handler, the interceptors and the response hook therefore lost an AsyncLocalStorage store that a request hook or an earlier middleware entered, as tracing and request-context libraries do. body-parser (through raw-body) and the content type parser of Fastify bind that callback to the context they were called in, so the store survives on Express and Fastify. A parser that has a body to read now binds next() to the context it was called in. It does so with an AsyncResource and runInAsyncScope(), as the interceptors of @nestjs/core do, rather than with AsyncResource.bind(), which is about 25 times slower: it adds about 45 ns to a request with a body, and nothing to one without.