S3: Close filehandle of versioned keys (#5587)

This commit is contained in:
Bert Blommers 2022-10-21 22:14:58 +00:00 committed by GitHub
parent 80ab997010
commit 6f710189ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -1455,12 +1455,10 @@ class S3Backend(BaseBackend, CloudWatchMetricProvider):
def reset(self):
# For every key and multipart, Moto opens a TemporaryFile to write the value of those keys
# Ensure that these TemporaryFile-objects are closed, and leave no filehandles open
for bucket in self.buckets.values():
for key in bucket.keys.values():
if isinstance(key, FakeKey):
key.dispose()
for mp in bucket.multiparts.values():
for mp in FakeMultipart.instances:
mp.dispose()
for key in FakeKey.instances:
key.dispose()
super().reset()
@property

View File

@ -56,6 +56,11 @@ class TestS3FileHandleClosures(TestCase):
def test_overwriting_file(self):
self.s3.put_object("my-bucket", "my-key", "b" * 10_000_000)
@verify_zero_warnings
def test_versioned_file(self):
self.s3.put_bucket_versioning("my-bucket", "Enabled")
self.s3.put_object("my-bucket", "my-key", "b" * 10_000_000)
@verify_zero_warnings
def test_copy_object(self):
key = self.s3.get_object("my-bucket", "my-key")