You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description or feature request:
Implement RequestsFetcher as a context manager and/or provide public cleanup method to be called by its users (for ex. fetcher.close() )
Current behavior: RequestsFetcher internlly tracks all exit paths to release allocated resources which is error prone.
Expected behavior:
Reliably release all resources allocated by RequestsFetcher.
I think fetch() being a CM might make sense (if it makes the client code nicer) but I don't believe it makes it any easier to handle cleanup...
The only resource (that requires handling) in RequestsFetcher is the requests.Response: this is tricky because we return a generator function that owns the Response but otherwise I think there's nothing that requires attention.
fetcher.close() could not solve any issues I believe: there is no object level "context" in fetcher itself that is problematic. fetch() does have to handle the Response but that can't be fixed with more methods as once we return the generator that owns the Response, it is no longer something the fetcher should or can worry about.
Reviving this issue after having a look at RequestsFetcher after a while.
Implementing fetch() as a context manager makes the default TUF implementation look better because now response is closed in a single place. For example:
@sechkova do you think this is still an active issue -- I think moving the download methods into Fetcher have solved the issues around this? I don't see our code having trouble with unclosed things currently
Activity
jku commentedon Mar 11, 2021
I think fetch() being a CM might make sense (if it makes the client code nicer) but I don't believe it makes it any easier to handle cleanup...
The only resource (that requires handling) in RequestsFetcher is the requests.Response: this is tricky because we return a generator function that owns the Response but otherwise I think there's nothing that requires attention.
fetcher.close()could not solve any issues I believe: there is no object level "context" in fetcher itself that is problematic.fetch()does have to handle the Response but that can't be fixed with more methods as once we return the generator that owns the Response, it is no longer something the fetcher should or can worry about.sechkova commentedon Jun 14, 2021
Reviving this issue after having a look at
RequestsFetcherafter a while.Implementing
fetch()as a context manager makes the default TUF implementation look better because nowresponseis closed in a single place. For example:requests_fetcher.py:
download.py:
But this also means adding a requirement to
FetcherInterface.fetch()to be a context manager and I can't decide if it is adding enough value?jku commentedon Sep 14, 2021
@sechkova do you think this is still an active issue -- I think moving the download methods into Fetcher have solved the issues around this? I don't see our code having trouble with unclosed things currently
sechkova commentedon Sep 14, 2021
Yeah, with
download_file()being context manager andRequestsFetchercorrectly cleaning up sockets, I think this is solved. Closing it.