From 95bf6b255d8ff7bb385567da498b90252efb338f Mon Sep 17 00:00:00 2001 From: TOGASHI Tomoki <81744248+toga4@users.noreply.github.com> Date: Tue, 7 May 2024 04:37:28 +0900 Subject: [PATCH] fix(pubsub): respect gRPC dial option when PUBSUB_EMULATOR_HOST is set (#10040) Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com> --- pubsub/pubsub.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pubsub/pubsub.go b/pubsub/pubsub.go index 29eea60e1f6f..e8250a3dbfce 100644 --- a/pubsub/pubsub.go +++ b/pubsub/pubsub.go @@ -29,6 +29,7 @@ import ( "cloud.google.com/go/pubsub/internal" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" "google.golang.org/grpc" "google.golang.org/grpc/keepalive" ) @@ -143,12 +144,14 @@ func NewClientWithConfig(ctx context.Context, projectID string, config *ClientCo // Environment variables for gcloud emulator: // https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub/ if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" { - conn, err := grpc.Dial(addr, grpc.WithInsecure()) - if err != nil { - return nil, fmt.Errorf("grpc.Dial: %w", err) + emulatorOpts := []option.ClientOption{ + option.WithEndpoint(addr), + option.WithGRPCDialOption(grpc.WithInsecure()), + option.WithoutAuthentication(), + option.WithTelemetryDisabled(), + internaloption.SkipDialSettingsValidation(), } - o = []option.ClientOption{option.WithGRPCConn(conn)} - o = append(o, option.WithTelemetryDisabled()) + opts = append(emulatorOpts, opts...) } else { numConns := runtime.GOMAXPROCS(0) if numConns > 4 {