Skip to content

Commit

Permalink
Fixed warnings about unclosed sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Jun 8, 2024
1 parent 6441ed6 commit a096a4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ xfail_strict = true
# Ignore resource warnings due to a CPython/Windows bug (https://bugs.python.org/issue44428)
filterwarnings = [
"error",
"ignore:unclosed <socket.socket.*:ResourceWarning",
"ignore:unclosed transport <_ProactorSocketTransport.*:ResourceWarning",
"ignore:ast.Str is deprecated:DeprecationWarning",
"ignore:Attribute s is deprecated:DeprecationWarning",
Expand Down
43 changes: 22 additions & 21 deletions tests/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,26 +491,27 @@ async def test_unretrieved_future_exception_server_crash(
def serve() -> None:
sock, addr = server_sock.accept()
event.wait(3)
sock.close()
del sock
gc.collect()

server_sock = socket.socket(family, socket.SOCK_STREAM)
server_sock.settimeout(1)
server_sock.bind(("localhost", 0))
server_sock.listen()
server_addr = server_sock.getsockname()[:2]
event = threading.Event()
thread = Thread(target=serve)
thread.start()
async with await connect_tcp(*server_addr) as stream:
await stream.send(b"GET")
event.set()
with pytest.raises(BrokenResourceError):
await stream.receive()
with socket.socket(family, socket.SOCK_STREAM) as server_sock:
server_sock.settimeout(1)
server_sock.bind(("localhost", 0))
server_sock.listen()
server_addr = server_sock.getsockname()[:2]
event = threading.Event()
thread = Thread(target=serve)
thread.start()
async with await connect_tcp(*server_addr) as stream:
await stream.send(b"GET")
event.set()
with pytest.raises(BrokenResourceError):
await stream.receive()

thread.join()
gc.collect()
assert not caplog.text
thread.join()
gc.collect()
assert not caplog.text


@pytest.mark.network
Expand Down Expand Up @@ -1042,12 +1043,12 @@ async def test_connecting_using_bytes(
)
async def test_connecting_with_non_utf8(self, socket_path: Path) -> None:
actual_path = str(socket_path).encode() + b"\xf0"
server = socket.socket(socket.AF_UNIX)
server.bind(actual_path)
server.listen(1)
with socket.socket(socket.AF_UNIX) as server:
server.bind(actual_path)
server.listen(1)

async with await connect_unix(actual_path):
pass
async with await connect_unix(actual_path):
pass


@pytest.mark.skipif(
Expand Down

0 comments on commit a096a4e

Please sign in to comment.