💬 Question here
If a request gets aborted than reply.send will log an ERR_STREAM_PREMATURE_CLOSE error if a strem was given to it. But should these kind of errors be treated as errors actually?
const {Readable} = require('stream')
const {setTimeout} = require('timers/promises')
const fastify = require('fastify')({
logger: true,
disableRequestLogging: true
});
fastify.get('/', async (req, res) => {
res.header('Content-Type', 'text')
await setTimeout(1000)
// abort the request before getting here
res.send(
new Readable({
read() {
this.push('whatever')
this.push(null)
}
})
)
// alternative stream: res.send(require('fs').createReadStream('package.json'))
});
fastify.listen(8080)
.catch(console.error)
If I cancel the ongoing request somehow (close the browser tab for example) within the delay in setTimeout then reply.send results in an ERR_STREAM_PREMATURE_CLOSE error. I also get errors if I test this example using autocannon and clinic. req.raw.aborted is true so shouldn't fastify handle aborted requests and don't throw an error in this case?
I found a comment in reply.js:
// We must not treat ERR_STREAM_PREMATURE_CLOSE as
// an error because it is created by eos, not by the stream.
But this part of the code is not called in this example. Could this be a bug?
Your Environment
- node version: 17
- fastify version: >=3.0.0
- os: Linux
💬 Question here
If a request gets aborted than reply.send will log an ERR_STREAM_PREMATURE_CLOSE error if a strem was given to it. But should these kind of errors be treated as errors actually?
If I cancel the ongoing request somehow (close the browser tab for example) within the delay in setTimeout then reply.send results in an ERR_STREAM_PREMATURE_CLOSE error. I also get errors if I test this example using autocannon and clinic. req.raw.aborted is true so shouldn't fastify handle aborted requests and don't throw an error in this case?
I found a comment in reply.js:
But this part of the code is not called in this example. Could this be a bug?
Your Environment