-
Notifications
You must be signed in to change notification settings - Fork 982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New async/await handler support breaks next(false)
functionality in current async handlers
#1935
Comments
Agree. This is making me consider switching framework. |
Kind of this also broke the express middleware support, although there has been no usage of async in own code. |
Calling Right now, all values are being discarded when returning a Lines 188 to 198 in adf24c1
|
Yes, I'm well aware it's not allowed. That's the whole point of this issue, as is the inability to stop chain processing. |
@ghermeto - have you agreed an approach to tackling this issue? We'd like to plan our upgrade path and that depends partly on which direction Restify takes here. |
You can workaround this by wrapping all async handlers, like the package https://www.npmjs.com/package/@gilbertco/restify-async-wrap does.
then
|
Do you have any idea how to use https://github.com/express-validator/express-validator middleware after the restify changes? Your wrapper doesn't work. |
@kolbma I'm using zod now to validate request inputs, and its just another middleware function on my routes. I'm sure it would be possible to still use express-validator if you wrap the middleware it exports in your own function and call it from your route. |
In an async handler you have to throw an error instead of calling But as I've written before there has been introduced some more new incompatibility with existing express middleware. E.g. I'm using express-validator middleware and with the newer restify versions I've to use a wrapper (thanks to @cjroebuck) like (TS)... async (req) => { await checkSchema(CHECK_SCHEMA).run(req); } With restify v8 I could simply use Do you have an idea what and where might be the problem to look for? |
No, because I don't want to throw an error. I want to stop the handler chain. |
@gmahomarf Ok, maybe one workaround would be to use I think #1941 would stop the handler chain if you have already handled request and response. IMO |
I don't want any errors when all I'm trying to do is stop the chain. I also don't like using next in async handlers, but there's currently no other way to stop the chain. That's the whole point of this issue. |
But you have to handle the request somehow or the tcp connection to the client is closed silently after timeout. So if you don't want to return an error you have at least to return some other response and there you close the response-writer and the handler chain would be stopped by itself. |
@kolbma this isn't the case if your code is running on a schedule, when no client is connected. We need the option to gracefully stop the chain. |
@phil-warner Could you explain what you mean by running code on a schedule? Sounds for me at the moment like async job scheduling in a bad way. The handler chain should be finished if the request is finished or you are open for Denial of Service. |
@kolbma sorry - that was inaccurate. I misread the code. Nonetheless, this should be supported without a workaround that people have to come to this thread to find. |
Restify Version: 10.0.0
Node.js Version: 16.8.1
Expected behaviour
Given a handler that does async work, I should be able to call
next(false);
and have the chain stop processing there.Actual behaviour
The handler arity checks prevent me from having handlers that use next and are async
Repro case
Code similar to this is used in one of our projects using restify v8. It breaks when trying to update to v10:
I am aware I could make my handler synchronous, then do
someAsyncWork().then(result => {...})
butasync/await
syntax was chosen for cleanliness and readability.Cause
node-restify/lib/chain.js
Lines 77 to 101 in 2053ef6
Are you willing and able to fix this?
This probably requires reworking the async chain stuff, so no.
The text was updated successfully, but these errors were encountered: