Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pubsub): respect gRPC dial option when PUBSUB_EMULATOR_HOST is set #10040

Merged
merged 6 commits into from May 6, 2024
13 changes: 8 additions & 5 deletions pubsub/pubsub.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down