aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory P. Smith <gps@google.com>2023-08-14 21:25:10 -0700
committerGitHub <noreply@github.com>2023-08-14 21:25:10 -0700
commit0b1a8ec5494281a809d294ef99179f26fa56be7f (patch)
treed77b461f03c4a3bd96e0d3531a30be04aeec8aa2
parent59a1020505d98edad569d009bc565337d0f5c17e (diff)
downloadportpicker-0b1a8ec5494281a809d294ef99179f26fa56be7f.tar.gz
Call `shutdown()` before `close()` to resolve potential flakiness. (#34)upstream-main
Bumps the version to 1.6.0 for a new official release.
-rw-r--r--ChangeLog.md8
-rw-r--r--setup.cfg3
-rw-r--r--src/portpicker.py8
3 files changed, 17 insertions, 2 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index b059d22..b32802e 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,6 +1,12 @@
+## 1.6.0
+
+* Resolve an internal source of potential flakiness on the bind/close port
+ checks when used in active environments by calling `.shutdown()` before
+ `.close()`.
+
## 1.6.0b1
-* Add -h and --help text to the command line tool.
+* Add `-h` and `--help` text to the command line tool.
* The command line interface now defaults to associating the returned port
with its parent process PID (usually the calling script) when no argument
was given as that makes more sense.
diff --git a/setup.cfg b/setup.cfg
index 1a5071e..f17d17c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,7 +1,7 @@
# https://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files
[metadata]
name = portpicker
-version = 1.6.0b1
+version = 1.6.0
maintainer = Google LLC
maintainer_email = greg@krypto.org
license = Apache 2.0
@@ -27,6 +27,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
+ Programming Language :: Python :: 3.12
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
platforms = POSIX, Windows
diff --git a/src/portpicker.py b/src/portpicker.py
index a887781..33805d4 100644
--- a/src/portpicker.py
+++ b/src/portpicker.py
@@ -155,6 +155,14 @@ def _bind(port, socket_type, socket_proto, return_socket=None,
return None
finally:
if return_socket is None or family != return_family:
+ try:
+ # Adding this resolved 1 in ~500 flakiness that we were
+ # seeing from an integration test framework managing a set
+ # of ports with is_port_free(). close() doesn't move the
+ # TCP state machine along quickly.
+ sock.shutdown(socket.SHUT_RDWR)
+ except OSError:
+ pass
sock.close()
if return_socket is not None and family == return_family:
return_socket.append(sock)