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

Incompatible with bluebird when set as global Promise. #121

Closed
mrfelton opened this issue Jun 23, 2017 · 13 comments
Closed

Incompatible with bluebird when set as global Promise. #121

mrfelton opened this issue Jun 23, 2017 · 13 comments

Comments

@mrfelton
Copy link

When used with bluebird, this error is thrown:

Error: the promise constructor cannot be invoked directly

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:

  1. You are trying to subclass Promise

Bluebird does not support extending promises this way. Instead, see scoped prototypes.>

It seems that in [email protected], it is now attempting to subclass the global Promise. So, if global Promise has been set as Bluebird this fails. [email protected] does not suffer from this problem.

@watson
Copy link
Collaborator

watson commented Jun 23, 2017

@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 1618234

cc @matthewloring @hayes @ofrobots

@hayes
Copy link
Collaborator

hayes commented Jun 23, 2017

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.

@hayes
Copy link
Collaborator

hayes commented Jun 23, 2017

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

@watson
Copy link
Collaborator

watson commented Jun 23, 2017

@hayes Yes good idea, I'll roll back for now

@mrfelton
Copy link
Author

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?

watson added a commit that referenced this issue Jun 23, 2017
This reverts commit d9b4de7 and
1618234.

Fixes #121
@hayes
Copy link
Collaborator

hayes commented Jun 23, 2017

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

@watson
Copy link
Collaborator

watson commented Jun 23, 2017

@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.

@watson
Copy link
Collaborator

watson commented Jun 23, 2017

yes, @hayes explanation is spot on

@watson
Copy link
Collaborator

watson commented Jun 23, 2017

@mrfelton this have now been fixed in v0.6.7

@mrfelton
Copy link
Author

Got it. Thanks for the detailed explanation @hayes . In my case, this module is being used as part of continuation-local-storage.

@hayes
Copy link
Collaborator

hayes commented Jun 23, 2017

You'll probably want to install https://www.npmjs.com/package/cls-bluebird

@hayes
Copy link
Collaborator

hayes commented Jun 23, 2017

Reopening because the fix was reverted due to an issue with bluebird

@hayes hayes reopened this Jun 23, 2017
@hayes
Copy link
Collaborator

hayes commented Jun 23, 2017

Reopened the wrong issue

@hayes hayes closed this as completed Jun 23, 2017
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

No branches or pull requests

3 participants