From b54df69fd2e6d37193a8154af15943480d0667f5 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Jun 2026 18:13:09 +0800 Subject: [PATCH 1/2] update_register Signed-off-by: root --- internal/server/register.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/server/register.go b/internal/server/register.go index a45b178..6ff80ee 100644 --- a/internal/server/register.go +++ b/internal/server/register.go @@ -161,18 +161,23 @@ func (ps *PluginServer) dial(unixSocketPath string, timeout time.Duration) (*grp } ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - c, _ := grpc.NewClient(unixSocketPath, + + target := "passthrough:///" + unixSocketPath + c, err := grpc.NewClient(target, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(func(ctx2 context.Context, addr string) (net.Conn, error) { var d net.Dialer return d.DialContext(ctx2, "unix", addr) }), ) + if err != nil { + return nil, fmt.Errorf("grpc.NewClient(%s): %w", target, err) + } // NewClient is non-blocking; block here to match the original WithBlock behaviour. - if !c.WaitForStateChange(ctx, connectivity.Ready) { + if !c.WaitForStateChange(ctx, connectivity.Idle) { c.Close() - return nil, ctx.Err() + return nil, fmt.Errorf("timed out waiting for connection to %s", unixSocketPath) } return c, nil From 0920f2381aa6afa9212aa0f30f9a90ff9216ee59 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Jun 2026 18:51:02 +0800 Subject: [PATCH 2/2] update Signed-off-by: root --- internal/server/register.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/server/register.go b/internal/server/register.go index 6ff80ee..5586d9b 100644 --- a/internal/server/register.go +++ b/internal/server/register.go @@ -174,11 +174,20 @@ func (ps *PluginServer) dial(unixSocketPath string, timeout time.Duration) (*grp return nil, fmt.Errorf("grpc.NewClient(%s): %w", target, err) } - // NewClient is non-blocking; block here to match the original WithBlock behaviour. - if !c.WaitForStateChange(ctx, connectivity.Idle) { - c.Close() - return nil, fmt.Errorf("timed out waiting for connection to %s", unixSocketPath) + c.Connect() + for { + state := c.GetState() + if state == connectivity.Ready { + return c, nil + } + if state == connectivity.TransientFailure || state == connectivity.Shutdown { + c.Close() + return nil, fmt.Errorf("connection to %s failed (state: %s)", unixSocketPath, state) + } + // Block until the state changes or the deadline is exceeded. + if !c.WaitForStateChange(ctx, state) { + c.Close() + return nil, fmt.Errorf("timed out waiting for connection to %s", unixSocketPath) + } } - - return c, nil }