fix: 首次握手失败停止重连并修正 Java 限速在途计数

This commit is contained in:
Nixevol
2026-09-30 17:33:52 +08:00
parent 0c9b459fb1
commit 4d2f6f0d03
6 changed files with 210 additions and 12 deletions
+16 -2
View File
@@ -227,6 +227,15 @@ class Client:
raise NixMsgError("not_connected", "连接超时")
err = self._handshake_error
if err:
with self._lock:
self._stop_reconnect = True
self._want_connected = False
if not self._last_stop_code:
code = getattr(err, "code", None) or "not_connected"
self._last_stop_code = str(code)
self._last_stop_err = err if isinstance(err, NixMsgError) else NixMsgError(
"not_connected", str(err)
)
raise err
if self._state not in (ConnectionState.ONLINE,):
if self._state == ConnectionState.AUTH_FAILED:
@@ -236,6 +245,11 @@ class Client:
)
if self._state == ConnectionState.KICKED:
raise NixMsgError("taken_over", "会话被接管")
with self._lock:
self._stop_reconnect = True
self._want_connected = False
self._last_stop_code = "not_connected"
self._last_stop_err = NixMsgError("not_connected", f"连接未成功: {self._state.value}")
raise NixMsgError("not_connected", f"连接未成功: {self._state.value}")
def close(self) -> None:
@@ -576,7 +590,7 @@ class Client:
except Exception:
pass
with self._lock:
self._handshake_error = NixMsgError("busy", "连接超时")
self._handshake_error = NixMsgError("not_connected", "连接超时")
return
def _on_transport_connected(self) -> None:
@@ -598,7 +612,7 @@ class Client:
self._pending[rid] = pending
self._transport.publish(up_topic(self._endpoint_id), dumps(hello))
if not pending.event.wait(self._connect_timeout_s):
raise NixMsgError("busy", "握手超时")
raise NixMsgError("not_connected", "握手超时")
if pending.error:
raise pending.error
assert pending.response is not None