Peach: Local-first video metadata scraper and media manager.
fix(desktop): 识别 accept 前客户端断开的 WinError 64 并只留本机记录
longmeidao1a51a56cf088
diff --git a/src/peach/error_reporting.py b/src/peach/error_reporting.pyindex 2a164044d..010730cb8 100644--- a/src/peach/error_reporting.py+++ b/src/peach/error_reporting.py@@ -366,8 +366,25 @@ def _finish_asyncio_connection_cleanup(context) -> bool:return True+def is_asyncio_accept_abort(error, context) -> bool:+ """识别客户端在 AcceptEx 完成前断开(WinError 64,ERROR_NETNAME_DELETED)的 accept 失败。++ 这是对端行为,不是 Peach 故障;但 CPython 3.14 的 Proactor `_start_serving` 在处理器+ 返回后会关掉监听套接字,这之后该端口不再接受连接。处理器拿不到重新挂 accept 所需的+ Server 与协议工厂,所以只识别和本机记录,不尝试恢复。+ """+ return (context.get("message") == "Accept failed on a socket"+ and isinstance(error, OSError) and getattr(error, "winerror", None) == 64+ and context.get("socket") is not None)++def asyncio_handler(loop, context) -> None:error = context.get("exception")+ if is_asyncio_accept_abort(error, context):+ # 默认处理器会经 asyncio 记录器写 ERROR 日志并远程上报,这里只留本机证据。+ local_event("unhandled-asyncio", error, message=context.get("message", ""),+ classification="accept-aborted", listener_closed=True)+ returnfields = _asyncio_fields(context)if is_asyncio_connection_cleanup(error, fields):fields["classification"] = "connection-cleanup"diff --git a/tests/test_error_reporting.py b/tests/test_error_reporting.pyindex a08932c65..4c0355184 100644--- a/tests/test_error_reporting.py+++ b/tests/test_error_reporting.py@@ -1086,6 +1086,40 @@ class ErrorReportingTests(unittest.TestCase):loop.diagnostic_socket.close.assert_called_once()loop.default_exception_handler.assert_not_called()+ def accept_failure(self, error):+ """按标准库 `_start_serving` 的形状调处理器:监听套接字仍有效时先报告,随后它会关掉监听。"""+ import socket+ from asyncio import trsock+ from peach import remote_reporting+ listener = socket.create_server(('127.0.0.1', 0))+ self.addCleanup(listener.close)+ loop = mock.Mock()+ with mock.patch.object(remote_reporting, 'send') as send:+ error_reporting.asyncio_handler(loop, {'message': 'Accept failed on a socket', 'exception': error,+ 'socket': trsock.TransportSocket(listener)})+ return loop, send++ def test_a_client_gone_before_accept_completes_is_recorded_locally_with_the_closed_listener(self):+ """WinError 64:客户端在 AcceptEx 完成前断开。处理器返回后标准库会关掉监听套接字,记录要写明。"""+ error = OSError(22, 'The specified network name is no longer available')+ error.winerror = 64+ loop, send = self.accept_failure(error)+ send.assert_not_called()+ loop.default_exception_handler.assert_not_called()+ record = self.records()[-1]+ self.assertEqual(record['stage'], 'unhandled-asyncio')+ self.assertEqual(record['classification'], 'accept-aborted')+ self.assertTrue(record['listener_closed'])+ self.assertEqual(record['exception'][0]['winerror'], 64)++ def test_other_accept_failures_keep_remote_evidence_and_the_default_handler(self):+ error = OSError(24, 'too many open files')+ error.winerror = 10024+ loop, send = self.accept_failure(error)+ send.assert_called_once()+ self.assertNotIn('classification', self.records()[-1])+ loop.default_exception_handler.assert_called_once()+def test_asyncio_tls_cleanup_keeps_protocol_class_after_application_detaches(self):from peach import remote_reportingerror = ConnectionResetError(10054, 'connection reset')