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

Handle RuntimeError #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions warcprox/mitmproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,17 @@ def status(self):

def process_request(self, request, client_address):
self.active_requests[request] = doublethink.utcnow()
future = self.pool.submit(
self.process_request_thread, request, client_address)
future.add_done_callback(
lambda f: self.active_requests.pop(request, None))
if future.done():
# avoid theoretical timing issue, in case process_request_thread
# managed to finish before future.add_done_callback() ran
try:
future = self.pool.submit(
self.process_request_thread, request, client_address)
future.add_done_callback(
lambda f: self.active_requests.pop(request, None))
if future.done():
# avoid theoretical timing issue, in case process_request_thread
# managed to finish before future.add_done_callback() ran
self.active_requests.pop(request, None)
except RuntimeError as exc:
self.logger.error("Error processing request %s", str(exc))
Copy link

Choose a reason for hiding this comment

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

you shouldn't call str(exc) that happens automatically because of %s if the error is logged and doesn't make that unneeded computation if it is filtered.

Additionally you could instead do, self.logger.error("Error processing request", exc_info=exc) than logging will add information about the exception by itself.

Before py3.5 sys.exc_info() will be used as bool(exc) is true
and after exc will be used directly.

https://docs.python.org/3/library/logging.html#logging.Logger.debug

self.active_requests.pop(request, None)

def get_request(self):
Expand Down