From f467c292daaf0ed9b9800c7e09468e01eb0e5d12 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 7 May 2019 21:20:04 +0000 Subject: [PATCH] session: add lock to fix hang Signed-off-by: Tibor Vass --- session/auth/authprovider/authprovider.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/session/auth/authprovider/authprovider.go b/session/auth/authprovider/authprovider.go index a286567e44d4..7df33cca4b95 100644 --- a/session/auth/authprovider/authprovider.go +++ b/session/auth/authprovider/authprovider.go @@ -3,6 +3,7 @@ package authprovider import ( "context" "io/ioutil" + "sync" "github.com/docker/cli/cli/config" "github.com/docker/cli/cli/config/configfile" @@ -19,6 +20,12 @@ func NewDockerAuthProvider() session.Attachable { type authProvider struct { config *configfile.ConfigFile + + // The need for this mutex is not well understood. + // Without it, the docker cli on OS X hangs when + // reading credentials from docker-credential-osxkeychain. + // See issue https://github.com/docker/cli/issues/1862 + mu sync.Mutex } func (ap *authProvider) Register(server *grpc.Server) { @@ -26,6 +33,8 @@ func (ap *authProvider) Register(server *grpc.Server) { } func (ap *authProvider) Credentials(ctx context.Context, req *auth.CredentialsRequest) (*auth.CredentialsResponse, error) { + ap.mu.Lock() + defer ap.mu.Unlock() if req.Host == "registry-1.docker.io" { req.Host = "https://index.docker.io/v1/" }