Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore exceptions on socket close #540

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: # Socket wasn't connected (nothing to shut down)
if exception.errno != errno.ENOTCONN:
raise

self.socket.close()

def __enter__(self) -> Self:
Expand Down
Loading