diff options
author | Michael Merickel <michael@merickel.org> | 2022-01-17 15:05:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-17 15:05:47 -0600 |
commit | 77276fdf3a2b191d13213a374be005ddc59f3db6 (patch) | |
tree | b30f9dabd801e7d1b29bba3d38d9bd4a69cea7bf | |
parent | f41e59826c81d7da5309e4b3694d5ac7a8bbd626 (diff) | |
parent | 5e990241fa71ab0f676b3ec6e8360aa47b3cf400 (diff) | |
download | waitress-77276fdf3a2b191d13213a374be005ddc59f3db6.tar.gz |
Merge pull request #358 from Pylons/bugfix/close-buffer
Close old buffer when overflowing in OverflowableBuffer
-rw-r--r-- | .github/workflows/ci-tests.yml | 10 | ||||
-rw-r--r-- | CHANGES.txt | 16 | ||||
-rw-r--r-- | src/waitress/buffers.py | 16 | ||||
-rw-r--r-- | src/waitress/trigger.py | 1 | ||||
-rw-r--r-- | tests/test_wasyncore.py | 1 |
5 files changed, 34 insertions, 10 deletions
diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 108a543..f28f6ca 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -15,11 +15,13 @@ jobs: strategy: matrix: py: - - "3.6" - "3.7" - "3.8" - "3.9" - - "pypy3" + - "3.10" + - "pypy-3.8" + # Pre-release + - "3.11.0-alpha - 3.11.0" os: - "ubuntu-latest" - "windows-latest" @@ -27,16 +29,12 @@ jobs: architecture: - x64 - x86 - exclude: # Linux and macOS don't have x86 python - os: "ubuntu-latest" architecture: x86 - os: "macos-latest" architecture: x86 - # Building on PyPy3 on Windows is broken - - os: "windows-latest" - py: "pypy3" name: "Python: ${{ matrix.py }}-${{ matrix.architecture }} on ${{ matrix.os }}" runs-on: ${{ matrix.os }} diff --git a/CHANGES.txt b/CHANGES.txt index ea28100..c45356e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,22 @@ Next Release ------------ +Bugfix +~~~~~~ + +- Fixed an issue whereby ``BytesIO`` objects were not properly closed, and + thereby would not get cleaned up until garbage collection would get around to + it. + + This led to potential for random memory spikes/memory issues, see + https://github.com/Pylons/waitress/pull/358 and + https://github.com/Pylons/waitress/issues/357 . + + With thanks to Florian Schulze for testing/vaidating this fix! + +Features +~~~~~~~~ + - Add REQUEST_URI to the WSGI environment. REQUEST_URI is similar to ``request_uri`` in nginx. It is a string that diff --git a/src/waitress/buffers.py b/src/waitress/buffers.py index 0086fe8..386eb40 100644 --- a/src/waitress/buffers.py +++ b/src/waitress/buffers.py @@ -234,11 +234,23 @@ class OverflowableBuffer: return buf def _set_small_buffer(self): - self.buf = BytesIOBasedBuffer(self.buf) + oldbuf = self.buf + self.buf = BytesIOBasedBuffer(oldbuf) + + # Attempt to close the old buffer + if hasattr(oldbuf, "close"): + oldbuf.close() + self.overflowed = False def _set_large_buffer(self): - self.buf = TempfileBasedBuffer(self.buf) + oldbuf = self.buf + self.buf = TempfileBasedBuffer(oldbuf) + + # Attempt to close the old buffer + if hasattr(oldbuf, "close"): + oldbuf.close() + self.overflowed = True def append(self, s): diff --git a/src/waitress/trigger.py b/src/waitress/trigger.py index 24c4d0d..3b1ad46 100644 --- a/src/waitress/trigger.py +++ b/src/waitress/trigger.py @@ -131,7 +131,6 @@ if os.name == "posix": def _physical_pull(self): os.write(self.trigger, b"x") - else: # pragma: no cover # Windows version; uses just sockets, because a pipe isn't select'able # on Windows. diff --git a/tests/test_wasyncore.py b/tests/test_wasyncore.py index 9f075e5..af9c3e5 100644 --- a/tests/test_wasyncore.py +++ b/tests/test_wasyncore.py @@ -405,7 +405,6 @@ if sys.platform.startswith("win"): # pragma: no cover def _unlink(filename): _waitfor(os.unlink, filename) - else: _unlink = os.unlink |