tornadoweb / tornadoweb/tornado
HTTPError creation raises an exception when connection is severed by the remote server during a long HTTPRequest
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 22.2k
- Forks
- 5.6k
- Avg merge
- 3h 42m
- Merged PRs (30d)
- 16
Description
When the remote server is shutdown before an HTTPRequest completes, the HTTPError exception fails to instantiate due to a TypeError in the string formatting of the error message. This prevents the real exception from being rethrown and passed in to the HTTPResponse object.
A non-integer code argument is passed at the exception instance creation. This prevents HTTPClient from creating the appropriate 5xx HTTPError to pass to the client for handling, as the compiler raises its own exception at trying to format a non-integer into an integer format place holder.
Apart from fixing the offending code that tries to create the HTTPError instance with non-integer code parameter (I couldn't actually track that one down to the source), I suggest to change the format string to use non-type specific formatting as per the mini string formatting language spec. This will at least prevent the runtime from choking at Exception creation.
Suggested fix:
In httpclient.py
class HTTPError(Exception):
....
def __init__(self, code, message=None, response=None):
self.code = code
message = message or httputil.responses.get(code, "Unknown")
self.response = response
Exception.__init__(self, "HTTP %d: %s" % (self.code, message))
change
Exception.__init__(self, "HTTP %d: %s" % (self.code, message))
to
Exception.__init__(self, "HTTP {}: {}" % (self.code, message))
letting Python manage the types.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in httpclient.py with HTTPError.init and trace how HTTPClient creates it when a remote server disconnects during an HTTPRequest. Verify that the error can be instantiated with the received code and that the underlying exception is passed to HTTPResponse without another formatting failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100