Fix(server,client): keep web terminal alive across heartbeat reconnects
The Go server answered TOKEN_HEARTBEAT with a 33-byte CMD_HEARTBEAT_ACK, while the Linux and Android clients gate the ACK on 1 + sizeof(HeartbeatACK) (1025 bytes) and silently drop anything shorter. Their application-level ACK watchdog therefore never got fed and disconnected the main connection every 60s. Each re-login replaced the whole hub.Device, wiping the screen/shell sub-conn bindings that ride their own TCP connections, so a web terminal kept receiving shell output while every keystroke was dropped — the "terminal goes unresponsive after a while" symptom — and the shell could no longer be torn down (orphan bash + leaked sockets). Clients now accept the 32-byte old ACK (Windows already did), and the server sends the full 1024-byte struct. Hub.Register carries the sub-conn session state across a re-login, and the disconnect cleanup is pinned to the connection it belongs to so a stale OnDisconnect cannot tear down a registration that has already replaced it. A shell sub-conn that can no longer be bound now tells the viewer instead of leaving the pane waiting. Verified on aa: RTT restored, zero "Heartbeat ACK timeout" lines, main-conn port stable; Go build/vet/test pass. Server deploy to the Go host is still pending, so un-upgraded clients will keep reconnecting until then. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
4aedca8ee0
commit
81f0d6c031
8 files changed
+412
-46
No files matched your search
@@ -1484,9 +1484,15 @@ int DataProcess(void* /*user*/, PBYTE szBuffer, ULONG ulLength)
|
||||
}
|
||||
|
||||
case CMD_HEARTBEAT_ACK:
|
||||
if (ulLength >= 1 + (ULONG)sizeof(HeartbeatACK)) {
|
||||
HeartbeatACK ack;
|
||||
memcpy(&ack, szBuffer + 1, sizeof(HeartbeatACK));
|
||||
// 完整结构 1024 字节;老服务端 / Go 服务端只回 HeartbeatACK_OldSize(32)。
|
||||
// 短包同样要喂 ACK 看门狗,否则每 60s 断开重连一次。Windows 端按
|
||||
// min(ulLength, 32) 兼容(KernelManager.cpp:2413)。
|
||||
if (ulLength >= 1 + (ULONG)HeartbeatACK_OldSize) {
|
||||
HeartbeatACK ack = {};
|
||||
const size_t copyLen = (ulLength - 1 >= sizeof(HeartbeatACK))
|
||||
? sizeof(HeartbeatACK)
|
||||
: (size_t)(ulLength - 1);
|
||||
memcpy(&ack, szBuffer + 1, copyLen);
|
||||
uint64_t now = GetUnixMs();
|
||||
g_lastHeartbeatAckMs.store(now, std::memory_order_relaxed);
|
||||
int64_t rtt = (int64_t)now - (int64_t)ack.Time;
|
||||
|
||||
Reference in new issue
Block a user