pubsub: Receive fails to hide context.Canceled error when using synchronous pull #3746
Labels
api: pubsub
Issues related to the Pub/Sub API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Client
PubSub
Environment
Various
Go Environment
$ go version
go version go1.16 linux/amd64
$ go env
Code
Expected behavior
The call to
sub.Receive
should return anil
error when it is terminated through context cancellation.Actual behavior
The call to
sub.Receive
returns a version ofcontext.Canceled
, wrapped/converted to a gRPC status error, if and only ifSynchronous
pull is enabled.Additional context
I've traced this so far as this error handling logic in
messageIterator.pullMessages
:google-cloud-go/pubsub/iterator.go
Lines 247 to 254 in 39517ae
In this case, it's trying to replace the context cancellation error with nil, but that cancellation error has already been wrapped into a gRPC one at this point ... which isn't surprising, because it came from a gRPC client call :)
I believe this can be fixed by updating the
switch
thus:The text was updated successfully, but these errors were encountered: