-
Notifications
You must be signed in to change notification settings - Fork 102
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
Don't completely crash server on uncaught exception #228
Conversation
src/hypercorn/trio/tcp_server.py
Outdated
@@ -48,28 +49,31 @@ async def run(self) -> None: | |||
socket = self.stream.socket | |||
ssl = False | |||
|
|||
def log_handler(e: Exception) -> None: | |||
if self.config.log.error_logger is not None: | |||
self.config.log.error_logger.exception("Internal hypercorn error") |
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 think you want error_logger.error("Internal hypercorn error", exc_info=e)
, because the exception being passed in might only be a slice of the exception group that was being caught, so the implicit "pull the current exception from ambient context" logic in error_logger.exception
might not grab the right data
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.
good call, done!
await self._start_idle() | ||
await self._read_data() | ||
except OSError: | ||
pass |
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.
There's a minor behavioral change here where we used to not log OSError
s, but now we do. Probably it's better to keep that, because OSError
s are probably like "the other side hung up" or similar and not interesting? I think you can do it with like
catch({OSError: ignore_handler, Exception: log_handler})
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.
done
@pgjones we just discovered the hard way that you reverted this... did you come up with the better solution you were looking for? Or could we un-revert it until you have a chance to replace with the proper fix? |
Partial mitigation for #225
This doesn't fix the underlying
AttributeError: 'WSStream' object has no attribute 'connection'
but it does allow the server to stay up and healthy when it encounters this bug.