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 21, 2023
1 parent 4ebf867 commit d38e931
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion 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 @@ -498,7 +499,12 @@ def __init__(self) -> None:
def close(self) -> None:
"""Close :attr:`.socket`."""
if self.socket is not None: # If initialized
self.socket.shutdown(socket.SHUT_RDWR)
try:
self.socket.shutdown(socket.SHUT_RDWR)
except OSError as exception: # Probably, the OS already closed the socket
if exception.errno != errno.ENOTCONN:
raise

self.socket.close()

def __enter__(self) -> Self:
Expand Down

0 comments on commit d38e931

Please sign in to comment.