Skip to content

Commit

Permalink
make sure we return the correct error with the last traceback.
Browse files Browse the repository at this point in the history
fix #630
  • Loading branch information
benoitc committed Mar 9, 2014
1 parent 41e7aba commit 0e4d9f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions gunicorn/workers/async.py
Expand Up @@ -7,6 +7,7 @@
import errno
import socket
import ssl
import sys

import gunicorn.http as http
import gunicorn.http.wsgi as wsgi
Expand Down Expand Up @@ -48,9 +49,13 @@ def handle(self, listener, client, addr):
except StopIteration as e:
self.log.debug("Closing connection. %s", e)
except ssl.SSLError:
raise # pass to next try-except level
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
except socket.error:
raise # pass to next try-except level
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
except Exception as e:
self.handle_error(req, client, addr, e)
except ssl.SSLError as e:
Expand Down
5 changes: 4 additions & 1 deletion gunicorn/workers/sync.py
Expand Up @@ -10,6 +10,7 @@
import select
import socket
import ssl
import sys

import gunicorn.http as http
import gunicorn.http.wsgi as wsgi
Expand Down Expand Up @@ -144,7 +145,9 @@ def handle_request(self, listener, req, client, addr):
if hasattr(respiter, "close"):
respiter.close()
except socket.error:
raise
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
except Exception:
if resp and resp.headers_sent:
# If the requests have already been sent, we should close the
Expand Down

2 comments on commit 0e4d9f0

@pdodde
Copy link

@pdodde pdodde commented on 0e4d9f0 Mar 11, 2014

Choose a reason for hiding this comment

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

The error we got was actually from sync.py around line 54. You may want to do the same thing there. I don't think this change will fix anybody's problem because it's not really a bug in your code, but it should let you point them in a different direction.

I think our problem might be that we tell the client we're sending them UTF-8 and then we send them something different. But that is still a guess.

@tilgovi
Copy link
Collaborator

Choose a reason for hiding this comment

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

@pdodde I think this is intended to fix the problem you describe.

This is the likely point at which the exception was re-raised. It is caught around line 54. The problem is that the raise call is raising last error, not the original error, which is why we cannot see what really went wrong.

At least, that's the hope.

Please sign in to comment.