-
Notifications
You must be signed in to change notification settings - Fork 52
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
Bug fix - listener leaks in case of nested wrapped methods and an error in the method #38
base: master
Are you sure you want to change the base?
Conversation
…ror, it pops the listenerStack only once, casing a leak of listeners into scopes they should not take effect on
Thanks for this patch! Unfortunately, some of your new tests aren't passing:
A few things have changed on master since you wrote this (I rebased your patch against current master), so it's possible things need a little adjustment. It's also possible that something's changed in iojs that's affected this. If you can get the tests passing or tweaked to your satisfaction, I'd be happy to merge this. |
…ror, it pops the listenerStack only once, casing a leak of listeners into scopes they should not take effect on
I have removed unneeded test - apparently something different has fixed the trigger for this fix - that if you imported domains after async listener you got some strange things happening. removed the obsolete test. |
But still, the PR is still valid - it fixes cases of nested callback wrapping |
The bug is subtle but still there -
If we have two nested methods that are both wrapped by
glue.js
, the result is that create will be called twice for the same tick. This by itself is not a big problem. The important thing is that the list of listeners is pushed twice intolistenersStack
However, if the callback passed to those two have an exception, the
asyncCatcher
method in glue.jsonly pops
listenersStack
once.Once example where this may happen is if we import domains after async-listener, the domain import causes
process.nextTick
to call async listener twice. The reason is because domain replaces the underlying_currentTickHandler
method. If domain is loaded after async listener, the_currentTickHandler
method is replaced with a wrapped method (wrapped by async listener).The net result is that
if we load async-listener, then domain, we will have both
process.nextTick
and_currentTickHandler
wrapped.if we load domain, then async-listener, we will have only
process.nextTick
wrapped.I have included two new test files to demonstrate the two cases as well as a fix to the problem. Just run the test cases without the fix and you can see the problem.
See the files
`````` double-calls-to-create-if-importing-domain-after-async-listener.tap.js
double-calls-to-create-not-happening-if-importing-domain-before-async-listener.tap.js```
Also note that the problem is not local to just domains. I have noticed that using
fs.readFile
callsfs.open
directly passing the same callback, resulting in nested wrapped methods and the same issue.