-
Notifications
You must be signed in to change notification settings - Fork 121
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
Request.finish called on a request after its connection was lost #11
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…request.finish. This is caused by either the client terminating the connection or a bug in the server. The default behavior is to allow request.write to be called when a handler completes successfully, and let twisted.web raise it's RuntimeError. However, the processingFailed code bath has been changed to guard against error handling being called when a request has already completed. This also allows this pattern: @route("/") def handler(request): d = someOperation() request.notifyFinish().addCallback(lambda _: d.cancel()) return d Which will effectively cancel someOperation when the client the disconnects, while the handler is waiting for the result of someOperation.
… the failure from processing_failed.
Conflicts: klein/test_resource.py
…deferred returned to klein by the handler if the connection is lost.
Conflicts: klein/test_resource.py
| request_finished[0] = True | ||
|
|
||
| request.notifyFinish().addBoth(_finish) | ||
|
|
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.
It's too bad Twisted's Request doesn't have a finished attribute.
|
The tests are good, and the code does what the tests expect. I've made a few inline comments. I think this is a good change. |
Conflicts: klein/test_resource.py
dreid
added a commit
that referenced
this pull request
Sep 7, 2013
Request.finish called on a request after its connection was lost
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
Thanks for Klein, it's really nice! I'm having an issue with requests failing because connections are closed before the response is finished. That leads to the following exception:
Normally I would handle that exception by doing
But this doesn't seem to work with Klein, since Klein adds both a callback and an errback that try to write useful information to the request. Of course I could just ignore it, but the error pollutes my logs and steal my attention from real errors. Have you encountered this problem, and if so, how do you handle it?