fix(agent): improve WebSocket and SSH fallback handling (#2441)

Make WebSocket reconnect and SSH fallback transitions reliable across asynchronous disconnects, stale callbacks, and overlapping connections. Keep the SSH listener available while disconnected and allow a verified WebSocket connection to take precedence when it recovers.

Co-authored-by: henrygd <hank@henrygd.me>
This commit is contained in:
spatiumstas
2026-10-01 20:33:19 +03:00
committed by henrygd
parent d8c2b1f310
commit 4ffd83677d
10 changed files with 688 additions and 65 deletions

View File

@@ -474,7 +474,7 @@ func TestWebSocketClient_HandleHubRequest(t *testing.T) {
Data: cbor.RawMessage{},
}
err := client.handleHubRequest(hubRequest, nil)
err := client.handleHubRequest(hubRequest, nil, nil)
if tc.expectError {
assert.Error(t, err)
@@ -536,6 +536,18 @@ func TestWebSocketClient_Close(t *testing.T) {
})
}
func TestWebSocketClient_IgnoresStaleClose(t *testing.T) {
agent := createTestAgent(t)
agent.connectionManager.eventChan = make(chan ConnectionEvent, 1)
current := &gws.Conn{}
client := &WebSocketClient{agent: agent, Conn: current, hubVerified: true}
client.OnClose(&gws.Conn{}, nil)
assert.Same(t, current, client.getConn())
assert.True(t, client.hubVerified)
assert.Empty(t, agent.connectionManager.eventChan)
}
// TestWebSocketClient_ConnectRateLimit tests connection rate limiting
func TestWebSocketClient_ConnectRateLimit(t *testing.T) {
agent := createTestAgent(t)