Closed mrfelton closed 7 years ago
@mrfelton Thanks for reporting this issue. Subclassing Promise was a fix for #112, but it was obviously not intended to have this side-effect.
I'm currently not sure if there is an easy fix for this besides rolling back 1618234d538cd36e8c167a495820147577369866
cc @matthewloring @hayes @ofrobots
Interesting. Async listener should not wrap non-native promises. I think there is a check for that, but it appears to not be working. I would look into making that check work, rather than trying to figure out how to wrapping bluebird promises.
Rolling back my not be a bad idea in the mean time, I suspect that more people is bluebird is likely more popular than any library that subclasses promises
@hayes Yes good idea, I'll roll back for now
Async listener should not wrap non-native promises. I think there is a check for that, but it appears to not be working.
Does that mean async-listener is not supposed to work with non-native promises? Or just that non-native promises don't need wrapping for some reason?
Non native promises are usually implemented using some other asynchronous api.to schedule work. This means that async listener hooks will already be fired. Some implementations I believe will implement their own queues and share async tasks from the real queues and execute multiple callbacks from their fake/custom task queues. In these cases it is likely/possible that async contexts could get confused. Async listener does not try to solve those types of issues (similar issues exist with connection pools), but consumers of the async listener API (apm agents, continuation-local-storage, etc) will generally add their own wrappers for these special cases. Often there is not a right way to handle these edge cases that applies to every use case, so the solution varies depending on what your using the app for
@mrfelton it should work as it's just vanilla javascript, but bluebird might have custom callback queues that make it a little tricky depending on your use-case. Personally I've needed to modify bluebird slightly to work well for my needs.
yes, @hayes explanation is spot on
@mrfelton this have now been fixed in v0.6.7
Got it. Thanks for the detailed explanation @hayes . In my case, this module is being used as part of continuation-local-storage.
You'll probably want to install https://www.npmjs.com/package/cls-bluebird
Reopening because the fix was reverted due to an issue with bluebird
Reopened the wrong issue
When used with bluebird, this error is thrown:
Which comes from here: http://bluebirdjs.com/docs/error-explanations.html#error-the-promise-constructor-cannot-be-invoked-directly
Note there it says one of the causes of this is:
It seems that in async-listener@0.6.6, it is now attempting to subclass the global Promise. So, if global Promise has been set as Bluebird this fails. async-listener@0.6.5 does not suffer from this problem.