-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix server not propagating errors on prehandler(promise) + handler error (#3242) #3358
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
Conversation
This commit fixes hapijs#3242; The fix basically revolves around running the promise handler on the nextTick, so that it would propogate upwards, but also explicitly binding a domain to a handler up in the chain of propogation, so that it's handled properly.
Can confirm this fixes #3242 - Thank you for this @turtleDev! |
@johnbrett it was a pleasure 😄 |
if (source instanceof Error) { | ||
return next(Boom.wrap(source)); | ||
} | ||
// do not use Hoek.nextTick because it will not work as intended |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no reason why hoek's wouldn't work here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hoek's nextTick drops context so this
would become invalid in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With an arrow function this shouldn't matter at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good point, what didn't work for you here @turtleDev?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, I'm not entirely sure. I tried using Hoek.nextTick
but it didn't somehow result in stack unwinding. maybe it has something to do with how domains work, but that's just a very un-informed guess.
My bad, Hoek.nextTick
will work, but it's not really suited for this situation. I looked into it, and it turns out, Hoek.nextTick
wraps up a function in process.nextTick
and returns the wrapped function ... but that means that you have to call the wrapped function, which here would seem redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/hapijs/hapi/pull/3202/files#diff-d86a59ede7d999db4b7bc43cb25a1c11R399, it doesn't have to be weird :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh yes, I realized this after I updated my comment. Thanks for pointing that out.
Looks very similar to the previous PR, doesn't exit the server anymore @johnbrett ? |
Yep - very similar @Marsup. It seems to be be that not using |
@johnbrett |
@johnbrett @Marsup Hello guys! Any updates on when this PR will be reviewed and /or merged? |
I'm 👍 on this, we're not the ones to convince, @hueniverse is. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
This patch proposes a fix for #3242 ;
The fix revolves around explicit domain bindings and execution of promise handler from the event loop (using process.nextTick) so that the error is not swallowed up by the promise itself (which was basically leading to a deadlock; the promise never fully resolved, and the callback is never called )
This is technically a bugfix, and I wasn't sure if I'm supposed to increase the patch version number, so I'll leave it up to you guys.