-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix critical unhandled error #28
Fix critical unhandled error #28
Conversation
headers = dict( | ||
(key, value) | ||
for (key, value) in headers.iteritems() | ||
if key != 'Content-Length' and key != 'content-length' |
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.
key.lower() != "content-length" is more readable.
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.
oops, yep, I had just introduced the .lower() in PR #26.
This is a merge with a past branch of mine ended poorly.
Thanks for taking the time to review Nicolas!
a251577
to
bc8051b
Compare
@@ -5,7 +5,6 @@ | |||
import os | |||
from urlparse import urlparse | |||
|
|||
import concurrent.futures | |||
import crochet | |||
from twisted.internet import reactor |
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.
importing reactor is something we know can lead to problems because it leads to itamarst/crochet#45 like issues
+1 for style and docs. The why behind the change is rough to understand, but I think we will be in a better place with this. |
bc8051b
to
907a11c
Compare
merged with #29, fixed issues, improved tests and documentation. acceptance tested with our internal ecosystem. |
DEFAULT_CONTENT_TYPE = 'application/json' | ||
|
||
# crochet defaults to infinite timeouts and that could cause hanging forever |
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.
How about "Sane defaults to prevent infinite timeouts"
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.
missed this, done now
lg2m |
🚢 |
|
b324768
to
24765d4
Compare
amended - just fixing comments and typos |
…r principle of least surprise - refactoring handler function
When travis complete, I think we are good to go! |
After having had an interest read from Twisted Programming Essentials I got an idea about what could be the cause for issue #27.
Possible causes
First, the way we are catching exceptions might be problematic. Here we should at least return the failure or raise the exception, but we are only setting the future's error. The book states:
Secondly, this is stated as a "please don't do" in crochet documentation as Twisted APIs are not thread safe and should not be called if not in the Twisted reactor thread. I believe we should put back the
@run_in_reactor
decorator at all costs.Solution
I am proposing here a way simpler solution (literally by the book, chapter "Web Clients - Agent") which solves the issue of CRITICAL errors #27 and seems to work properly with our internal system. The general idea is that there is no need for futures as the EventualResult object from crochet already acts as some sort of future. Hence there's no need to set results/exceptions in the future ourselves, as the EventualResult does it already flawlessly and without risk of losing 'unhandled exceptions' as it was happening.
Testing
Finally, I tested this client with our services and our acceptance suite was all green.