diff --git a/src/python/grpcio_tests/tests/unit/_reconnect_test.py b/src/python/grpcio_tests/tests/unit/_reconnect_test.py index 8d7fd38868b..b19a5b5d76f 100644 --- a/src/python/grpcio_tests/tests/unit/_reconnect_test.py +++ b/src/python/grpcio_tests/tests/unit/_reconnect_test.py @@ -42,7 +42,7 @@ class ReconnectTest(unittest.TestCase): 'UnaryUnary': grpc.unary_unary_rpc_method_handler(_handle_unary_unary) }) - options=(('grpc.so_reuseport', 0),) + options=(('grpc.so_reuseport', 1),) with bound_socket() as (host, port): addr = '{}:{}'.format(host, port) server = grpc.server(server_pool, (handler,), options=options) diff --git a/src/python/grpcio_tests/tests/unit/framework/common/__init__.py b/src/python/grpcio_tests/tests/unit/framework/common/__init__.py index e1979c96b09..488c712c704 100644 --- a/src/python/grpcio_tests/tests/unit/framework/common/__init__.py +++ b/src/python/grpcio_tests/tests/unit/framework/common/__init__.py @@ -15,7 +15,6 @@ import contextlib import socket - def get_socket(bind_address='localhost', listen=True, sock_options=(socket.SO_REUSEPORT,)): @@ -49,6 +48,7 @@ def get_socket(bind_address='localhost', sock.listen(1) return bind_address, sock.getsockname()[1], sock except socket.error: + sock.close() continue raise RuntimeError("Failed to bind to {} with sock_options {}".format( bind_address, sock_options))