From 67bc954a30c9b8e96e58b745d2cef2ea19f9f7bf Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Fri, 5 May 2023 17:52:41 +0100 Subject: [PATCH] attempt to throttle spawning lots of daemons before the first is ready --- cli/internal/daemon/connector/connector.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/internal/daemon/connector/connector.go b/cli/internal/daemon/connector/connector.go index f8742d317807b..3df2025d88609 100644 --- a/cli/internal/daemon/connector/connector.go +++ b/cli/internal/daemon/connector/connector.go @@ -128,6 +128,7 @@ const ( _maxAttempts = 10 _shutdownTimeout = 1 * time.Second _socketPollTimeout = 1 * time.Second + _notReadyTimeout = 3 * time.Millisecond ) // killLiveServer tells a running server to shut down. This method is also responsible @@ -254,8 +255,11 @@ func (c *Connector) connectInternal(ctx context.Context) (*Client, error) { } // Loops back around and tries again. } else if errors.Is(err, errUnavailable) { - // close the client, see if we can kill the stale daemon + // The rust daemon will open the socket a few ms before it's ready to accept connections. + // If we get here, we know that the socket exists, but the server isn't ready yet. + // We'll wait a few ms and try again. c.Logger.Debug("server not ready yet") + time.Sleep(_notReadyTimeout) } else if err != nil { // Some other error occurred, close the client and // report the error to the user