From 7076fef5fef81cce47dbfbab3d7257cc7d3776bc Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Mon, 28 Jun 2021 18:18:24 -0700 Subject: [PATCH] fix(pubsub): retry GOAWAY errors (#4313) The frontend server for Pub/Sub might occasionally emit GOAWAY errors which are currently not retried. This is not unique to the Go client, though the categorization as `UNKNOWN` vs `UNVAILABLE` is a golang-GRPC issue. Although UNKNOWN [should not generally be retried](https://google.aip.dev/194), this will unblock users of `Receive` until the grpc library can be changed. See internal cl/377393940 for a similar fix in another Go library. Fixes #4257. --- pubsub/service.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pubsub/service.go b/pubsub/service.go index d9a00021eb0..0c24be25a69 100644 --- a/pubsub/service.go +++ b/pubsub/service.go @@ -62,6 +62,14 @@ func (r *defaultRetryer) Retry(err error) (pause time.Duration, shouldRetry bool return r.bo.Pause(), true } return 0, false + case codes.Unknown: + // Retry GOAWAY, see https://github.com/googleapis/google-cloud-go/issues/4257. + isGoaway := strings.Contains(s.Message(), "error reading from server: EOF") && + strings.Contains(s.Message(), "received prior goaway") + if isGoaway { + return r.bo.Pause(), true + } + return 0, false default: return 0, false }