This commit is contained in:
2026-02-04 20:51:54 -08:00
parent b714d477a6
commit d806ebad85
9 changed files with 257 additions and 63 deletions

View File

@@ -872,13 +872,20 @@ class MPVIPCClient:
try:
if self.is_windows:
# BinaryIO pipe from open('\\\\.\\pipe\\...')
pipe = cast(BinaryIO, self.sock)
pipe.write(payload.encode("utf-8"))
pipe.flush()
try:
pipe.write(payload.encode("utf-8"))
pipe.flush()
except OSError as e:
# Windows Errno 22 (EINVAL) often means the pipe handle is now invalid/closed
if getattr(e, "errno", 0) == 22:
raise BrokenPipeError(str(e))
raise
else:
sock_obj = cast(socket.socket, self.sock)
sock_obj.sendall(payload.encode("utf-8"))
except (OSError, IOError, BrokenPipeError) as exc:
except (OSError, IOError, BrokenPipeError, ConnectionResetError) as exc:
# Pipe became invalid (disconnected, corrupted, etc.).
# Disconnect and attempt one reconnection.
if not self.silent:
@@ -889,12 +896,17 @@ class MPVIPCClient:
try:
if self.is_windows:
pipe = cast(BinaryIO, self.sock)
pipe.write(payload.encode("utf-8"))
pipe.flush()
try:
pipe.write(payload.encode("utf-8"))
pipe.flush()
except OSError as e:
if getattr(e, "errno", 0) == 22:
raise BrokenPipeError(str(e))
raise
else:
sock_obj = cast(socket.socket, self.sock)
sock_obj.sendall(payload.encode("utf-8"))
except (OSError, IOError, BrokenPipeError) as retry_exc:
except (OSError, IOError, BrokenPipeError, ConnectionResetError) as retry_exc:
self.disconnect()
raise MPVIPCError(f"Pipe write failed after reconnect: {retry_exc}") from retry_exc
else:
@@ -912,7 +924,7 @@ class MPVIPCClient:
try:
pipe = cast(BinaryIO, self.sock)
return pipe.readline()
except (OSError, IOError, BrokenPipeError) as exc:
except (OSError, IOError, BrokenPipeError, ConnectionResetError) as exc:
# Pipe error; try to reconnect once
if not self.silent:
debug(f"Pipe readline failed: {exc}")