-
Notifications
You must be signed in to change notification settings - Fork 35
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
[EDITED] Document cancel-after-final-timeout pattern #102
Comments
Hi, thanks for the detailed bug report! Just back from a vacation so catching up with things; I'll try to get you an answer soon. |
Hi, thanks very much for your answer! Please let me know what you think, I'm really curious about getting a second opinion. |
So... the If the interaction pattern is "if timeout is hit we're done", perhaps you want to use |
@lucagiovagnoli any thoughts on the above? |
hi! thanks for your reply and sorry for my delayed answer (I am supposed to be back working on this next week). What I was looking for was something which:
|
Oh, I see. So this is for fire-and-forget operations, just something you want to start in the background? |
exactly. As in my example above, my deferred is returned from the Twisted Agent request, so I'd like to be able to fire the network call and retrieve results later |
Retrieving results later isn't really fire-and-forget though. So OK, it's not that use case. The use case is then... "I've started a Twisted thing in background with Can you do this:
|
I think that could actually solve my problem! I missed the eventual_result could be canceled from outside while going crazy with twisted deferreds. Thanks for taking the time and for the other pair of eyes. Will try that out but feel free to close this cause I feel confident that's the way to go |
I'm thinking maybe some documentation of this pattern would be useful, so will this open for that. |
I encountered an issue with crochet not terminating the twisted deferred correctly when raising the TimeoutError exception.
Code for reference
Traceback
Everything was going fine (TimeoutError is correctly raised) but the twisted reactor thread was failing due to the connection closing incorrectly. Traceback:
All assertion were true, showing that no exception is trapped in the EventualResult. Exception happens exactly when the eventual_result is garbage collected.
The problem
From Twisted documentation:
In this case the ConnectionLost exception is caused by the garbage collector disposing of the deferred when we lose all references to the EventualResult (and hence the deferred). In fact we don't see anything logged until the eventual_result is alive.
I think that raising TimeoutError here without disposing of the deferred is causing the Agent connection to be closed incorrectly and the exception to be thrown in the reactor thread after raising the TimeoutError.
Verification
As a last step to verify the problem I added self.cancel() before raising the TimeoutError so that the deferred is cancelled properly.
I tested this with our internal acceptance test suite.
Why not handling twisted.internet.error.ConnectionLost with a twisted errback?
The problem is a systematic erroneous disposal of the deferred object causing the connection to be always incorrectly closed the same way. Let's say I was to handle this on our side this way:
I would be mistakenly catching all potential connectionLost issues, even the ones due to other causes (for example the server aborting the connection).
Action points
I understand crochet would not want to dispose of deferred objects before raising the TimeoutError to allow multiple retries on result retrieval.
Q: Would crochet be interested in a way to dispose/destroy the deferred ? Something as this on stackoverflow. Otherwise I am conducting the same discussion to handle this on our side.
The text was updated successfully, but these errors were encountered: