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 bug has not already been reported
Fastify version
4.4.0
Plugin version
3.1.0
Node.js version
16
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Manjaro 22
Description
I try to hook this plugin into a normal fastify project, but I got a crash issue.
Steps to Reproduce
Here is a sample to reproduce:
constsetTimeout=require('timers/promises').setTimeout;constfastify=require('fastify')();constcb=require('@fastify/circuit-breaker');fastify.register(cb).after(err=>{if(err){console.trace(`register plugins failed: ${err.message}`);throwerr;}}).register(router);asyncfunctionrouter(fastify){fastify.register(controller,{prefix: '/'});fastify.addHook('preHandler',fastify.circuitBreaker());}asyncfunctioncontroller(fastify){fastify.get('/',asyncfunction(req,reply){// make a long time request manually, and expect a timeout responseawaitsetTimeout(60000);reply.code(200).send({health: 'OK'});});// ... Omit other URL handling}fastify.listen({port: 3000},err=>{if(err)throwerrconsole.log('Server listening at http://localhost:3000')})
I have a normal action fastify.get('/'), and I wish this plugin could work when timeout.
node index.js
# open another terminal
curl -v localhost:3000
And curl seems working (but why I have to wait until 1 min, not default 10 s?):
$ curl -v localhost:3000
* Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.86.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 503 Service Unavailable
< content-type: application/json; charset=utf-8
< content-length: 109
< Date: Wed, 21 Dec 2022 15:09:53 GMT
< Connection: keep-alive
< Keep-Alive: timeout=72
<
* Connection #0 to host localhost left intact
{"statusCode":503,"code":"FST_ERR_CIRCUIT_BREAKER_TIMEOUT","error":"Service Unavailable","message":"Timeout"}
And node index.js crashed:
$ node index.js
Server listening at http://localhost:3000
node:events:491
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at new NodeError (node:internal/errors:393:5)
at ServerResponse.end (node:_http_outgoing:968:15)
at /tmp/tmp/node_modules/fastify/lib/error-handler.js:43:17
at fallbackErrorHandler (/tmp/tmp/node_modules/fastify/lib/error-handler.js:130:3)
at handleError (/tmp/tmp/node_modules/fastify/lib/error-handler.js:33:5)
at onErrorHook (/tmp/tmp/node_modules/fastify/lib/reply.js:742:5)
at wrapOnSendEnd (/tmp/tmp/node_modules/fastify/lib/reply.js:535:5)
at handleReject (/tmp/tmp/node_modules/fastify/lib/hooks.js:238:5)
Emitted 'error' event on ServerResponse instance at:
at emitErrorNt (node:_http_outgoing:827:9)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}
Expected Behavior
I hope I can get timeout response when circuit-breaker trigger timeout event, and fastify instance should not crashed.
The text was updated successfully, but these errors were encountered:
fastify.get('/', async function (req, reply) {
// make a long time request manually, and expect a timeout response
await setTimeout(60000);
- reply.code(200).send({health: 'OK'});+ return {health: 'OK'}
});
Prerequisites
Fastify version
4.4.0
Plugin version
3.1.0
Node.js version
16
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Manjaro 22
Description
I try to hook this plugin into a normal fastify project, but I got a crash issue.
Steps to Reproduce
Here is a sample to reproduce:
I have a normal action
fastify.get('/')
, and I wish this plugin could work when timeout.node index.js # open another terminal curl -v localhost:3000
And
curl
seems working (but why I have to wait until 1 min, not default 10 s?):And
node index.js
crashed:Expected Behavior
I hope I can get timeout response when circuit-breaker trigger timeout event, and fastify instance should not crashed.
The text was updated successfully, but these errors were encountered: