Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

QueuTask: prevent unhandled exception from tearing the main loop down #108

Merged
merged 1 commit into from May 20, 2016

Conversation

djipko
Copy link
Contributor

@djipko djipko commented May 19, 2016

Prior to this patch - raising an exception inside an execute() of a
queued
task when using futures instead of deferreds, would tear down the whole
service thread. This is almost certainly not what we want.

The cleanest way to fix this seems to be in the ExecutionContext, where
we consider an exception handled if it's set on a future, and let the
submitter worry about it.

@ghost ghost added the CLA Signed label May 19, 2016
@fmoo
Copy link
Contributor

fmoo commented May 20, 2016

So, there's no guarantee that the person who created the future is going to wait for the result, but I think this is the right tradeoff in behavior.

@@ -201,6 +201,7 @@ def set_exception(self, exception):
self.timer.stop()
if self.future is not None:
self.future.set_exception(exception)
handled = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment above, like:

# For future-based work, let's allow the submitter to handle the exception
# gracefully.  Since we can't know if that was successful, just assume the
# exception will be handled (or re-raised) by someone awaiting the future.
# This isn't guaranteed, but is a reasonable assumption.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do - thanks! In case of QueueTask - this decision makes sense since submit() returns a future instance so it's basically a part of it's public API.

Also in QueueTask.map() we rely on the future to throw to the caller as we call result() on it.

Prior to this patch - raising an exception inside an execute() of a
queued
task when using futures instead of deferreds, would tear down the whole
service thread. This is almost certainly not what we want.

The cleanest way to fix this seems to be in the ExecutionContext, where
we consider an exception handled if it's set on a future, and let the
submitter worry about it.
@fmoo fmoo merged commit 046ea44 into facebookarchive:master May 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants