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
I have searched existing issues to ensure the regression has not already been reported
Last working version
3.x.x
Stopped working in version
4.0.0-4.0.3
Node.js version
16-18
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Arch 202206
💥 Regression Report
Undere some conditions fastify responds with an empty response, occasionally logging errors about premature termination or headers sent.
This was first encountered in compressed responses (fastify-compress) after upgrading to v4, when responses started coming back empty and premature termination/ socket closures where reported in logs.
Upon furthere investigation it seems that there is a regression after kReplySent was refactored, when using async handlers and sending a stream response via reply.send
The return statement is crucial and part of the documented breaking changes. You have to do:
fastify.get('/ok',async(request,reply)=>{conststream=newReadable()stream._read=()=>{}stream.push(payload)stream.push(null)awaitnewPromise((resolve)=>{setTimeout(resolve,100).unref()})reply.header('Content-Type','text/plain').send(stream)returnreply// this is crucial})
Should Typescript typings exclude undefined return type from handlers to help catch these issues? e.g. T extends Promise<infer I> ? () => Promise<Exclude<I, undefined>> : () => Exclude<T, undefined>.
We kind of shot ourselvese in the foot with this, and only updated to return reply now.
Prerequisites
Last working version
3.x.x
Stopped working in version
4.0.0-4.0.3
Node.js version
16-18
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Arch 202206
💥 Regression Report
Undere some conditions fastify responds with an empty response, occasionally logging errors about premature termination or headers sent.
This was first encountered in compressed responses (fastify-compress) after upgrading to v4, when responses started coming back empty and premature termination/ socket closures where reported in logs.
Upon furthere investigation it seems that there is a regression after kReplySent was refactored, when using async handlers and sending a stream response via
reply.send
The condition here
fastify/lib/wrapThenable.js
Line 21 in 00f4088
send(undefined)
which responds before stream is written.Potentially related to #4018, #3994,
Not related fastify/fastify-compress#215
Steps to Reproduce
Test in 282e8e0 or
Basic example:
Expected Behavior
Fastify responds with
hello world...
in broken handler.reply.send(stream)
is not raced byreply.send(undefined)
in https://github.com/fastify/fastify/blob/main/lib/wrapThenable.jsThe text was updated successfully, but these errors were encountered: