Performance implications if next is not called in the middleware?

33 views
Skip to first unread message

node...@gmail.com

unread,
Dec 27, 2017, 2:18:51 AM12/27/17
to nodejs

In the middleware function, to move on to the succeeding middleware function, we need to invoke the next function. As we all know, if we omit the call the next() function, the request will be hanging. In these scenarios, are there any performance implications due to this? If yes, then what are those issues? What might be the issues if we do not explicitly call next function and requests are left hanging?


Thank you.

Michaël Rouges

unread,
Dec 28, 2017, 2:48:47 AM12/28/17
to nod...@googlegroups.com
The next() call isn't related to the perfs... it's only to let the possibility to have another middleware to treat the request.

I do the same thing in my AJAX client library : anticore ;)

Michaël Rouges - https://github.com/Lcfvs - @Lcfvs

2017-12-27 1:31 GMT+01:00 <node...@gmail.com>:

In the middleware function, to move on to the succeeding middleware function, we need to invoke the next function. As we all know, if we omit the call the next() function, the request will be hanging. In these scenarios, are there any performance implications due to this? If yes, then what are those issues? What might be the issues if we do not explicitly call next function and requests are left hanging?


Thank you.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/4215b2d6-4392-4f9e-9551-ea714659af6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zlatko

unread,
Dec 28, 2017, 3:41:42 PM12/28/17
to nodejs


On Wednesday, December 27, 2017 at 8:18:51 AM UTC+1, node...@gmail.com wrote:

In the middleware function, to move on to the succeeding middleware function, we need to invoke the next function. As we all know, if we omit the call the next() function, the request will be hanging. In these scenarios, are there any performance implications due to this? If yes, then what are those issues? What might be the issues if we do not explicitly call next function and requests are left hanging?



This depends on the clients, settings, etc. If the clients close the requests or timeout, and if there aren't that many of them, you might do fine. After a client disconnects, express will clean up and close your request (usually). The thing is though, until the connection closes, this request is left hanging. And with it all other request-allocated resources, such as session info etc. So if enough of the requests pile up, you might run out of memory or other resources. You also might have some resources open, locked, or whatever, and you require next middleware or error middleware or someone else to clean this up. E.g. depending of what libs you use, you might end up with one that is lousy and opens one db connection per request, and you run out of pool of db connections, so all other ops are left waiting for timeouts and requests closed etc.

So it can get to performance or even more, stability issues. It's usually not a super smart thing to leave middleware hanging.


Reply all
Reply to author
Forward
0 new messages