-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
S3 Multipart uploads comitted on exception when using compression via context manager #684
Comments
Thank you for reporting this. Are you interested in making a PR? |
Not right now, sorry. |
Any update? If not I can try to fix it |
No updates on this. Yes, please go ahead. |
I think the problem is here: https://github.com/RaRe-Technologies/smart_open/blob/18128f15e50c5ceda065a6d7d041eab6cb0933ad/smart_open/compression.py#L140 We should be making the result of compression_wrapper a context manager too, so it cleans up the underlying stream correctly. Right? |
I think is not enough. We already have a tweak_close: def tweak_close(outer, inner):
"""Ensure that closing the `outer` stream closes the `inner` stream as well.
Use this when your compression library's `close` method does not
automatically close the underlying filestream. See
https://github.com/RaRe-Technologies/smart_open/issues/630 for an
explanation why that is a problem for smart_open.
"""
outer_close = outer.close
def close_both(*args):
nonlocal inner
try:
outer_close()
finally:
if inner:
inner, fp = None, inner
fp.close()
outer.close = close_both Which close underlying streams but in the case of S3 MultipartWriter we want to terminate (abort) uploading if an error is raised. So I see that when an exception is thrown |
That sounds right. Is tweak_close able to determine when it is being called as part of exception handling? If not, we may have to look at the stack. |
@mpenkov I'm not sure how to determine when it is being called as part of exception handling or not so I decided to use |
similar issue with Azure #783 |
using |
Problem description
This is because when using a context manager around a compressed file, the
MultipartWriter
__exit__
method will not be called on https://github.com/RaRe-Technologies/smart_open/blob/59d3a6079b523c030c78a3935622cf94405ce052/smart_open/s3.py#L938-L942We've seen two resulting behaviours from this issue:
__exit__
is not called correctlySteps/code to reproduce the problem
Versions
The text was updated successfully, but these errors were encountered: