-
Notifications
You must be signed in to change notification settings - Fork 50
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
Calls to async.applyEachSeries must include an explicit callback #26
base: master
Are you sure you want to change the base?
Conversation
Not sure if this is a related issue or not, but I get the same issue with next being
This worked fine with SC 9.x, the issue only surfaced once we upgraded to a more recent version. |
@UppaJung Sorry for the delay in response. The current code is intended behaviour, the last function passed to the The |
@BenV Support for this use case was not added explicitly but I'll try to fix this. |
@UppaJung Could you confirm if your middleware function had the current number of arguments? Could this be the root of your issue or something else? The test cases which cover middleware are passing. Note that middleware functions should be in the form |
@BenV I tested your use case, passing an |
Ahh interesting, makes sense. Thanks for looking into it! |
@jondubois: If the SocketCluster code can be called in a way that causes undefined to be passed to a "next" function, does that not imply there's either a bug or the parameters aren't being checked correctly? Here's the code we have been using, with both a error print out if next is undefined and some extra code to make sure that never happens even if SocketCluster passes us a null next function. It indeed has a function which is of the form (req, next).
|
@UppaJung It sure looks like you're running into the same issue I was with using async/await. I got around this by simply using a non-async wrapper function for the middleware logic, but it sounds like you can also return a promise instead of using |
@jondubois: Is the behavior for async/await documented anywhere? I can change my code to work the way you say it's supposed to work, but there's at least a documentation bug if nobody who reads the documentation knows this is how it's supposed to work. When I look at the documentation for addMiddleware, there's nothing that tells me that if my function returns a promise I can't also call next. |
When you call async.applyEachSeries with a sequence of arguments that ends in a function, it assumes that the final argument is a callback that should be triggered when the series is complete.
https://caolan.github.io/async/docs.html#applyEachSeries
In the use cases fixed in this PR, async.applyEachSeries is used to call middleware where the final parameter to the middleware is the next function.
Since the next is a function, and was the final parameter to applyEachSeries, applyEachSeries assumed it was the optional callback that can be provided as a final parameter, and not the final parameter to be passed to the middleware. When calling the middleware, undefined was sent in place of the next parameter. Middleware that actually needed to call the next parameter received an undefined value.
This PR ensures that the next function is indeed passed as the final parameter to the middleware.