Skip to content

speech/apiv2: NewClient(ctx, option.withEndpoint) crashes with busyloop when streaming using gRPC #11625

@tonymet

Description

@tonymet

options.WithEndpoint("us-central1-speech.googleapis.com") causes a busy loop at func (c *gRPCClient) BatchRecognize(c in speech_client.go L1392

Setting the port number avoids this issue. (e.g. client, err = speech.NewClient(ctx, option.WithEndpoint("us-central1-speech.googleapis.com:443"))

Client

  • cloud.google.com/go/speech v1.26.0 // indirect

Environment

  • Debian 12.9
  • Linux 5.15.167.4-microsoft-standard-WSL2
  • x86_64 GNU/Linux
  • go version go1.23.4 linux/amd64

Code and Dependencies

package main
func main() {
 
ctx, _ = context.WithTimeout(context.Background(), time.Minute*5)
client, err = speech.NewClient(ctx, option.WithEndpoint("us-central1-speech.googleapis.com"), option.WithGRPCDialOption(grpc.WithDisableRetry()))
	
err := recognizeRequest(optOutput, optInput)
}



func recognizeRequest(outputPath, inputPath string) error {
	resp, err := client.BatchRecognize(ctx, &speechpb.BatchRecognizeRequest{
		//Recognizer: fmt.Sprintf("projects/%s/locations/global/recognizers/_", GOOGLE_PROJECT_ID),
		Recognizer: fmt.Sprintf("projects/%s/locations/us-central1/recognizers/low-cost-standard", GOOGLE_PROJECT_ID),
		Config:     &speechpb.RecognitionConfig{LanguageCodes: []string{"en_US"}, Model: "long", DecodingConfig: &speechpb.RecognitionConfig_AutoDecodingConfig{}},
		Files: []*speechpb.BatchRecognizeFileMetadata{
			{AudioSource: &speechpb.BatchRecognizeFileMetadata_Uri{Uri: inputPath}},
		},
		RecognitionOutputConfig: &speechpb.RecognitionOutputConfig{
			Output: &speechpb.RecognitionOutputConfig_GcsOutputConfig{
				GcsOutputConfig: &speechpb.GcsOutputConfig{Uri: outputPath},
			},
		},
		ProcessingStrategy: speechpb.BatchRecognizeRequest_DYNAMIC_BATCHING,
	},
	)
	if err != nil {
		log.Fatalf("failed to recognize: %v", err)
	}
	fmt.Fprintf(os.Stderr, "response: %s\n", resp.Name())
	return nil
}
go.mod
module modname

go 1.24.0

require (
        cloud.google.com/go v0.116.0 // indirect
        cloud.google.com/go/auth v0.13.0 // indirect
        cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
        cloud.google.com/go/compute/metadata v0.6.0 // indirect
        cloud.google.com/go/longrunning v0.6.2 // indirect
        cloud.google.com/go/speech v1.26.0 // indirect
        github.com/felixge/httpsnoop v1.0.4 // indirect
        github.com/go-logr/logr v1.4.2 // indirect
        github.com/go-logr/stdr v1.2.2 // indirect
        github.com/google/s2a-go v0.1.8 // indirect
        github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
        github.com/googleapis/gax-go/v2 v2.14.0 // indirect
        go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
        go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
        go.opentelemetry.io/otel v1.29.0 // indirect
        go.opentelemetry.io/otel/metric v1.29.0 // indirect
        go.opentelemetry.io/otel/trace v1.29.0 // indirect
        golang.org/x/crypto v0.31.0 // indirect
        golang.org/x/net v0.33.0 // indirect
        golang.org/x/oauth2 v0.24.0 // indirect
        golang.org/x/sync v0.10.0 // indirect
        golang.org/x/sys v0.28.0 // indirect
        golang.org/x/text v0.21.0 // indirect
        golang.org/x/time v0.8.0 // indirect
        google.golang.org/api v0.214.0 // indirect
        google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
        google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
        google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
        google.golang.org/grpc v1.67.3 // indirect
        google.golang.org/protobuf v1.35.2 // indirect
)

STEPS TO REPRODUCE

  1. set breakpoint at speech_client.go L1392
  2. build and run the above code
  3. watch for hitting of breakpoint

Expected behavior

BatchRecognize request complete in a few seconds & request is in the operation queue

Actual behavior

cpu hits > 50% . breakpoint @ speech_client.go L1392 triggers infinitely

Screenshots

n/a

Workarounds

  • explicit set endpoint with PORT number .e.g "us-central1-speech.googleapis.com:443" fixes the issue
  • attempted workaround grpc.WithDisableRetry() did not fix the issue (first hypothesis was a retry loop)

Metadata

Metadata

Assignees

Labels

api: speechIssues related to the Speech-to-Text API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions