Reconnect proxy connection even if shutdown was scheduled before.

This commit is contained in:
Joachim Bauch 2025-10-23 14:28:50 +02:00
commit 6956df67c8
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 40 additions and 10 deletions

View file

@ -759,11 +759,6 @@ func (c *mcuProxyConnection) scheduleReconnect() {
}
c.close()
if c.IsShutdownScheduled() {
c.proxy.removeConnection(c)
return
}
interval := c.reconnectInterval.Load()
// Prevent all servers from reconnecting at the same time in case of an
// interrupted connection to the proxy or a restart.
@ -812,11 +807,6 @@ func (c *mcuProxyConnection) reconnect() {
return
}
if c.IsShutdownScheduled() {
c.proxy.removeConnection(c)
return
}
log.Printf("Connected to %s", c)
c.closed.Store(false)
c.helloProcessed.Store(false)

View file

@ -2501,6 +2501,46 @@ func Test_ProxyReconnectAfter(t *testing.T) {
}
}
func Test_ProxyReconnectAfterShutdown(t *testing.T) {
CatchLogForTest(t)
t.Parallel()
require := require.New(t)
assert := assert.New(t)
server := NewProxyServerForTest(t, "DE")
mcu, _ := newMcuProxyForTestWithOptions(t, proxyTestOptions{
servers: []*TestProxyServerHandler{server},
}, 0)
connections := mcu.getSortedConnections(nil)
require.Len(connections, 1)
sessionId := connections[0].SessionId()
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
client := server.GetSingleClient()
require.NotNil(client)
client.sendMessage(&ProxyServerMessage{
Type: "event",
Event: &EventProxyServerMessage{
Type: "shutdown-scheduled",
},
})
// Force reconnect.
client.close()
assert.NoError(mcu.WaitForDisconnected(ctx))
// The client will automatically reconnect and resume the session.
time.Sleep(10 * time.Millisecond)
assert.NoError(mcu.WaitForConnections(ctx))
if connections := mcu.getSortedConnections(nil); assert.Len(connections, 1) {
assert.Equal(sessionId, connections[0].SessionId())
}
}
func Test_ProxyResume(t *testing.T) {
CatchLogForTest(t)
t.Parallel()