Skip to content

Commit

Permalink
Ensure returned port is ready to be used after get_ephermeral_port
Browse files Browse the repository at this point in the history
…finishes executing by ensuring socket is shutdown
  • Loading branch information
chazkii committed Apr 16, 2020
1 parent b21eef7 commit 5b70115
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pytest-server-fixtures/pytest_server_fixtures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ def get_ephemeral_port(port=0, host=None, cache_host=True):
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
port = s.getsockname()[1]
s.shutdown(socket.SHUT_RDWR)
s.close()
return port
except socket.error:
except socket.error as e:
if e.errno == errno.ENOTCONN:
return port
port = random.randrange(1024, 32768)


Expand Down

0 comments on commit 5b70115

Please sign in to comment.