Skip to content
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

Close old buffer when overflowing in OverflowableBuffer #358

Merged
merged 4 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@ 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"
- "macos-latest"
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 }}
Expand Down
16 changes: 16 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/waitress/buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,23 @@ def _create_buffer(self):
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):
Expand Down
1 change: 0 additions & 1 deletion src/waitress/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def _close(self):
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.
Expand Down
1 change: 0 additions & 1 deletion tests/test_wasyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ def _waitfor(func, pathname, waitall=False):
def _unlink(filename):
_waitfor(os.unlink, filename)


else:
_unlink = os.unlink

Expand Down