@@ -165,19 +165,33 @@ func (ps *PluginServer) dial(unixSocketPath string, timeout time.Duration) (*grp
165165 }
166166 ctx , cancel := context .WithTimeout (context .Background (), timeout )
167167 defer cancel ()
168- c , _ := grpc .NewClient (unixSocketPath ,
168+
169+ target := "passthrough:///" + unixSocketPath
170+ c , err := grpc .NewClient (target ,
169171 grpc .WithTransportCredentials (insecure .NewCredentials ()),
170172 grpc .WithContextDialer (func (ctx2 context.Context , addr string ) (net.Conn , error ) {
171173 var d net.Dialer
172174 return d .DialContext (ctx2 , "unix" , addr )
173175 }),
174176 )
175-
176- // NewClient is non-blocking; block here to match the original WithBlock behaviour.
177- if ! c .WaitForStateChange (ctx , connectivity .Ready ) {
178- c .Close ()
179- return nil , ctx .Err ()
177+ if err != nil {
178+ return nil , fmt .Errorf ("grpc.NewClient(%s): %w" , target , err )
180179 }
181180
182- return c , nil
181+ c .Connect ()
182+ for {
183+ state := c .GetState ()
184+ if state == connectivity .Ready {
185+ return c , nil
186+ }
187+ if state == connectivity .TransientFailure || state == connectivity .Shutdown {
188+ c .Close ()
189+ return nil , fmt .Errorf ("connection to %s failed (state: %s)" , unixSocketPath , state )
190+ }
191+ // Block until the state changes or the deadline is exceeded.
192+ if ! c .WaitForStateChange (ctx , state ) {
193+ c .Close ()
194+ return nil , fmt .Errorf ("timed out waiting for connection to %s" , unixSocketPath )
195+ }
196+ }
183197}
0 commit comments