Skip to content

Commit

Permalink
HTTPRequest: close file uploads to prevent ResourceWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
perrinjerome committed Jan 4, 2025
1 parent 2a97b18 commit e7de506
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
5.11.2 (unreleased)
-------------------

- Fix a ``ResourceWarning`` emitted when uploading large files.
(`#1242 <https://github.com/zopefoundation/Zope/issues/1242>`_)

- OFS/cachable: fix *Cache this object using* label in ZMI.

- Include versions constraints for production and non-production dependencies
Expand Down
3 changes: 3 additions & 0 deletions src/ZPublisher/HTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def clear(self):
self.stdin = None
self._file = None
self._fs = None
for f in self.form.values():
if isinstance(f, FileUpload):
f.close()
self.form.clear()
# we want to clear the lazy dict here because BaseRequests don't have
# one. Without this, there's the possibility of memory leaking
Expand Down
3 changes: 2 additions & 1 deletion src/ZPublisher/tests/testHTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ def test_processInputs_w_large_input_gets_tempfile(self):
self.assertTrue(f.name)
self.assertEqual(40006, len(f.file.read()))
self.assertTrue(f.file.fileno())
f.file.close()
req.clear()
self.assertTrue(f.file.closed)

def test_processInputs_with_file_upload_gets_iterator(self):
# checks fileupload object supports the iterator protocol
Expand Down

0 comments on commit e7de506

Please sign in to comment.