Skip to content

Commit

Permalink
give disable command timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Jan 23, 2024
1 parent ff85860 commit 28dd0cf
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ func (cr *Cluster) Enable(ctx context.Context) (err error) {
ctx, cancel := context.WithTimeout(keepaliveCtx, KeepAliveInterval/2)
defer cancel()
if !cr.KeepAlive(ctx) {
logInfo("Reconnecting due to keepalive failed")
cr.Disable(keepaliveCtx)
logError("TODO: figure out what caused infinite reconnect")
os.Exit(0xfe)
if !cr.Connect(keepaliveCtx) {
logError("Cannot reconnect to server, exit.")
os.Exit(1)
}
if err := cr.Enable(keepaliveCtx); err != nil {
logError("Cannot enable cluster:", err, "; exit.")
os.Exit(1)
if keepaliveCtx.Err() == nil {
logInfo("Reconnecting due to keepalive failed")
cr.Disable(keepaliveCtx)
if !cr.Connect(keepaliveCtx) {
logError("Cannot reconnect to server, exit.")
os.Exit(1)
}
if err := cr.Enable(keepaliveCtx); err != nil {
logError("Cannot enable cluster:", err, "; exit.")
os.Exit(1)
}
}
}
}, KeepAliveInterval)
Expand Down Expand Up @@ -303,12 +303,17 @@ func (cr *Cluster) Disable(ctx context.Context) (ok bool) {
cr.KeepAlive(tctx)
cancel()
}
data, err := cr.socket.EmitAckContext(ctx, "disable")

tctx, cancel := context.WithTimeout(ctx, time.Second*10)
data, err := cr.socket.EmitAckContext(tctx, "disable")
cancel()

cr.enabled.Store(false)
cr.socket.Close()
cr.socket = nil
close(cr.disabled)
if err != nil {
logErrorf("Disable failed: %v", err)
return false
}
logDebug("disable ack:", data)
Expand Down Expand Up @@ -754,7 +759,7 @@ func (cr *Cluster) DownloadFile(ctx context.Context, dir string, hash string) (e
if ok {
select {
case <-done:
case <-cr.disabled:
case <-cr.Disabled():
}
return
}
Expand Down

0 comments on commit 28dd0cf

Please sign in to comment.