Skip to content

Commit

Permalink
Ignore exceptions on socket close
Browse files Browse the repository at this point in the history
  • Loading branch information
PerchunPak committed May 13, 2023
1 parent 981253f commit 4b623ba
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mcstatus/protocol/connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import errno
import socket
import struct
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -507,8 +508,9 @@ def __enter__(self) -> Self:
def __exit__(self, *_) -> None:
try:
self.close()
except Exception:
pass
except OSError as exception: # Probably, the OS already closed the socket
if exception.errno != errno.ENOTCONN:
raise


class TCPSocketConnection(SocketConnection):
Expand Down Expand Up @@ -621,8 +623,9 @@ async def __aenter__(self) -> Self:
async def __aexit__(self, *_) -> None:
try:
self.close()
except Exception:
pass
except OSError as exception: # Probably, the OS already closed the socket
if exception.errno != errno.ENOTCONN:
raise


class UDPAsyncSocketConnection(BaseAsyncConnection):
Expand Down Expand Up @@ -670,5 +673,6 @@ async def __aenter__(self) -> Self:
async def __aexit__(self, *_) -> None:
try:
self.close()
except Exception:
pass
except OSError as exception:
if exception.errno != errno.ENOTCONN: # Probably, the OS already closed the socket
raise

0 comments on commit 4b623ba

Please sign in to comment.