From 3bf9396713c7de898663a2c26d0f3d7061b30467 Mon Sep 17 00:00:00 2001 From: Michael Boeckli Date: Mon, 5 Aug 2024 14:07:12 +0200 Subject: [PATCH] ARCO-105: When restarting, cancel writer, reader and disconnect so that reconnect routine will recreate connections --- peer.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/peer.go b/peer.go index 4173de8..8e7e918 100644 --- a/peer.go +++ b/peer.go @@ -422,10 +422,7 @@ func (p *Peer) startReadHandler(ctx context.Context) { p.logger.Error("Retrying to read failed", slog.String(errKey, err.Error())) // stop all read and write handlers - p.cancelWriteHandler() - p.cancelReadHandler() - - p.disconnectLock() + p.Restart() return } @@ -719,10 +716,7 @@ func (p *Peer) startWriteChannelHandler(ctx context.Context, instance int) { p.logger.Error("Failed retrying to write message", slog.Int("instance", instance), slog.String(errKey, err.Error())) // stop all read and write handlers - p.cancelWriteHandler() - p.cancelReadHandler() - - p.disconnectLock() + p.Restart() return } @@ -856,9 +850,15 @@ func (p *Peer) IsHealthy() bool { } func (p *Peer) Restart() { - p.Shutdown() + if p.cancelWriteHandler != nil { + p.cancelWriteHandler() + } - p.start() + if p.cancelReadHandler != nil { + p.cancelReadHandler() + } + + p.disconnectLock() } func (p *Peer) Shutdown() {