-
Notifications
You must be signed in to change notification settings - Fork 982
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
When using handleUncaughtExceptions, if an error is thrown within a stream callback in the uncaughtException
handler, restify enters an infinite loop.
#1749
Comments
One of my concerns with this is that it makes this problematic behavior silent. Would it be useful to know whether the error handler actually throws or emit an error than is not handled? If so, would setting up a custom error event handler that:
be a better trade-off between silencing all errors that occur in the error handler and consuming resources without bounds? Another question that I have is: is it possible for an error to be emitted or thrown in the domain error handler before resources associated with the request/response are released? If so, would those resources ever be released if the error handler is set using |
Yes, I definitely think that's ideal.
That does sound like a reasonable proposal to me. Any idea what you'd think such an API would look like?
That I'm not sure of. I could do more testing on Node to get a lower-level understanding. Regardless, I think that it would be ideal to solve this such that we can ensure that Restify always releases resources, if possible. |
@cprussin I'm thinking that prescribing/enforcing any behavior in restify is going to be tricky, because it seems difficult to determine what the best way is for restify consumers to handle those edge cases. Is it possible for you to implement those ideas in a new domain within that restify domain error handler? |
We can definitely do that @misterdjules. Being that that's the case, Restify using |
@cprussin I'm not sure anymore that For instance, it seems like a legitimate use case for restify's uncaughtException handler is to log errors that are emitted on the req and res objects, or any other emitter created in the context of req/res' domain. Using Thoughts on that? |
@misterdjules yeah, that's a good point. Depending on what happens with the upstream node issue, we could also consider changing restify to create a new domain and call Lines 829 to 831 in 4900d6b
handlerDomain.on('error', function onError(err) {
var errorDomain = domain.create();
errorDomain.on('error', function onError(err) {
// Do something with err, probably including telling app
// authors how they can handle this more gracefully...
});
errorDomain.run(function run() {
self._onHandlerError(err, req, res, true);
});
}); That way, we avoid an infinite loop in restify, but apps can still do error detection within the uncaught exception handler (by creating yet another new domain...). |
@cprussin Very interesting! Would the I presume it could at the very least log an error too, even though I wonder if that would drown into a sea of logs and turn out to be not that useful. |
@misterdjules I would think it likely should do both of those, but OTOH is there an argument to be had that in this scenario, we should kill the process? |
@cprussin I don't know about killing the process, since the goal of using domains in the first place is to not exit on uncaught exceptions. I'm starting to think that all this should be left to the consumer of Restify because they have the most context on how they want their application to behave. That is valid for nodejs/node#26211 too, and so I'm starting to think that is not a desirable change too. Regardless, we could definitely improve Restify's and domain's documentation by documenting those edge cases and available workarounds. Thoughts? |
@misterdjules I agree that the ultimate insights into that an exception occurred should be up to the app, but I think that having a mode where the tool can enter an infinite loop unexpectedly (or at least, due to a condition that isn't obvious) is a problem--entering an unexpected infinite loop is a worse condition than crashing the process anyways. However, the more we chat about this, the more I think that the problem isn't Restify's to solve. Because of that, I'm actually really in favor of your change to Node, but I still think we should document those edge cases when using the restify flag so that consuming apps know how to account for these cases. So my viewpoint on this is:
|
Bug Report
Restify Version
Tested on
7.7.0
, almost definitely present in all versions due to underlying Node issue.Node.js Version
v10.15.1
, likely present in all versions of Node.Expected behaviour
No infinite loop
Actual behaviour
Infinite loop
Repro case
Cause
This is caused by this issue in node.
Are you willing and able to fix this?
Yes.
There is a workaround available for this issue, which would be to change
on
toonce
here. If the restify team is on board with this change, I'm happy to submit a PR.The text was updated successfully, but these errors were encountered: