Skip to content
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

Optionally use setImmediate instead of nextTick in middleware #1081

Merged
merged 3 commits into from
Jan 20, 2016

Conversation

bhuga
Copy link
Contributor

@bhuga bhuga commented Nov 11, 2015

When upgrading from node 0.8 to 0.10, we were failing with errors like this:

... snip ...
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.

node.js:0
// Copyright Joyent, Inc. and other Node contributors.
^
RangeError: Maximum call stack size exceeded

This uses setImmediate instead of nextTick if available, allowing our hubot to boot.

cc @technicalpickles

@technicalpickles
Copy link
Member

Maybe this would be better on Robot than middleware? There's stuff in listener using it too.

@bhuga
Copy link
Contributor Author

bhuga commented Nov 12, 2015

Maybe this would be better on Robot than middleware? There's stuff in listener using it too.

nextTick is not deprecated entirely, only when used recursively. That's how we use it in middleware. I got the use case in listener that's recursive and left the other one alone.

@bhuga bhuga mentioned this pull request Nov 12, 2015
@technicalpickles
Copy link
Member

Sounds good then 👍

@michaelansel
Copy link
Collaborator

Hmm.. the docs recommend using process.nextTick if you are async-ifying a function: https://nodejs.org/api/process.html#process_process_nexttick_callback_arg

The reason the warning is there is because the behavior changed from "after I/O" to "before I/O" in 0.10. I think we are okay with blocking I/O here, so that warning is noise. I wonder if it got removed in later versions...

@bhuga
Copy link
Contributor Author

bhuga commented Nov 13, 2015

The reason the warning is there is because the behavior changed from "after I/O" to "before I/O" in 0.10.

Not just that. nextTick was officially deprecated in recursive contexts, which our middleware turns out to be. We still have a few other nextTicks that are fine; only the ones done in the middleware's inner loop are bad. Ctrl-f for 'recursive' in https://github.com/nodejs/node/wiki/API-changes-between-v0.8-and-v0.10.

I'm going to release 2.17 without this. We haven't been running it and I want to do our upgrade internally before the rest of the world tests it extensively.

@bhuga
Copy link
Contributor Author

bhuga commented Nov 23, 2015

We've been using this for about a week and no catastrophes have popped up. Any objections to merging it?

@technicalpickles
Copy link
Member

We've been using this for awhile without problem, so it's good to merge & release.

technicalpickles added a commit that referenced this pull request Jan 20, 2016
Optionally use setImmediate instead of nextTick in middleware
@technicalpickles technicalpickles merged commit e2e25fa into master Jan 20, 2016
@technicalpickles technicalpickles deleted the node-variable-ticker branch January 20, 2016 03:45
@technicalpickles technicalpickles mentioned this pull request Jan 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants