mirror of
https://github.com/henrygd/beszel.git
synced 2026-10-02 22:37:47 +02:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user