fix(pubsub/v2): prevent nil span panic in Subscriber.Receive#14278
Merged
hongalex merged 1 commit intogoogleapis:mainfrom Mar 31, 2026
Merged
fix(pubsub/v2): prevent nil span panic in Subscriber.Receive#14278hongalex merged 1 commit intogoogleapis:mainfrom
hongalex merged 1 commit intogoogleapis:mainfrom
Conversation
When tracing is enabled, the concurrency control span (ccSpan) is only assigned if the ack ID is found in activeSpans. However, ccSpan.End() was called unconditionally when tracing is enabled, causing a nil pointer panic when the ack ID was not in the map. Add a nil check before calling ccSpan.End() to prevent the panic. Fixes googleapis#14277
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds a null check for ccSpan in the Receive method of the subscriber. The review feedback suggests simplifying the conditional check by removing the redundant iter.enableTracing flag, as the null check for ccSpan is sufficient.
hongalex
approved these changes
Mar 31, 2026
bhshkh
approved these changes
Mar 31, 2026
hongalex
added a commit
that referenced
this pull request
Mar 31, 2026
PR created by the Librarian CLI to initialize a release. Merging this PR will auto trigger a release. Librarian Version: v0.8.3 Language Image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian-go@sha256:f8558b849eab319c3b9fc0b0ee8cab738b7e0b88e746275c759b38b194247a42 <details><summary>pubsub/v2: v2.5.1</summary> ## [v2.5.1](pubsub/v2.5.0...pubsub/v2.5.1) (2026-03-31) ### Bug Fixes * prevent nil span panic in Subscriber.Receive (#14278) ([c590c35](c590c350)) </details>
fredrikaverpil
added a commit
to einride/cloudrunner-go
that referenced
this pull request
Apr 1, 2026
fredrikaverpil
added a commit
to einride/cloudrunner-go
that referenced
this pull request
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
When tracing is enabled on a pubsub v2 subscriber, there is a race between the subscriber loop and the ack/nack/expiry paths.
activeSpansis async.Mapshared across goroutines, and the span can be deleted between theStore(message received initer.receive) and theLoad(message dispatched inSubscriber.Receive):iter.receive()stores the subscribe span inactiveSpans(iterator.go:382)keepAliveDeadlinescleanup callsactiveSpans.LoadAndDelete(iterator.go:582)sendAckcallsactiveSpans.LoadAndDelete(iterator.go:659)sendModAckwithisNack=truecallsactiveSpans.LoadAndDelete(iterator.go:739)activeSpans.Load(ackh.ackID)returnsok=false, soccSpanstays nil (subscriber.go:408)ccSpan.End()panics on nil (subscriber.go:427)What?
Add a nil check before calling
ccSpan.End(). If the parent subscribe span was already removed fromactiveSpans, there is nothing to link the concurrency control span to — skipping it seems like the correct semantic behavior.Notes
The issue reporter (@magnusewe) noted "this started happening after the client had been running for a while", which aligns with message expiry being the most likely trigger.
Fixes #14277