restify / restify/node-restify
New async/await handler support breaks `next(false)` functionality in current async handlers
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 975
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 5
Description
- Used appropriate template for the issue type
- Searched both open and closed issues for duplicates of this issue
- Title adequately and concisely reflects the feature or the bug
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:
server.use(async (req, res, next) => {
const result = await someAsyncWork();
if (shouldStop(result)) {
res.send({something: 'here'});
next(false);
return;
}
// ... more work
next();
});
I am aware I could make my handler synchronous, then do someAsyncWork().then(result => {...}) but async/await syntax was chosen for cleanliness and readability.
Cause
Are you willing and able to fix this?
This probably requires reworking the async chain stuff, so no.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading lib/chain.js around lines 77-101, then reproduce the reported behavior with the async handler example using restify 10. The work is done when an async handler can call next(false) to stop processing while retaining async/await support.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100