mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/cli: add timeout for newSocketControlClient
On BSD platform, using "daemon -r" may fool the status check that ctrld is still running while it was terminated unexpectedly. This may cause the check in newSocketControlClient hangs forever. Using a sane timeout value of 30 seconds, which should be enough for the ctrld service started in normal condition.
This commit is contained in:
committed by
Cuong Manh Le
parent
810cbd1f4f
commit
203a2ec8b8
@@ -2065,6 +2065,8 @@ func newSocketControlClient(s service.Service, dir string) *controlClient {
|
||||
ctx := context.Background()
|
||||
|
||||
cc := newControlClient(filepath.Join(dir, ctrldControlUnixSock))
|
||||
timeout := time.NewTimer(30 * time.Second)
|
||||
defer timeout.Stop()
|
||||
|
||||
// The socket control server may not start yet, so attempt to ping
|
||||
// it until we got a response. For each iteration, check ctrld status
|
||||
@@ -2084,6 +2086,11 @@ func newSocketControlClient(s service.Service, dir string) *controlClient {
|
||||
}
|
||||
// The socket control server is not ready yet, backoff for waiting it to be ready.
|
||||
bo.BackOff(ctx, err)
|
||||
select {
|
||||
case <-timeout.C:
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user