Skip to content

Commit

Permalink
ARCO-105: When restarting, cancel writer, reader and disconnect so th…
Browse files Browse the repository at this point in the history
…at reconnect routine will recreate connections
  • Loading branch information
boecklim committed Aug 5, 2024
1 parent 08a38f5 commit 3bf9396
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 3bf9396

Please sign in to comment.