Demo for NodeJS preemption bugs via node::MakeCallback.
Usage:
- node 0.12.0 should be on your PATH
- grab all the files from this gist into the same directory
node-gyp rebuild
to compile preemptor.cc into build/Release/preemptor.nodenode demo
to run the demo
For me, the demo output is
initialize state to 1
benign callback that does not change state, invoked directly
State should be 1, is actually 1
benign callback that does not change state, invoked via MakeCallback
End of tick! Change state from 1 to 2
State should be 1, is actually 2
tick over, state should be 2, is actually 2
Note that "benign callback, invoked via MakeCallback" also caused the tick to end, and the other nextTick callback changes externally observable state at a bad time, corrupting the world from the point of view of the outer code that should not have been preempted but was.