[英]GCM (legacy FCM) sends GOAWAY HTTP/2 frames
Our push backend uses GCM API to send notifications to Android devices.我们的推送后端使用GCM API向 Android 设备发送通知。
Endpoint: https://fcm.googleapis.com/fcm/send
端点:
https://fcm.googleapis.com/fcm/send
HTTP client: Java 11 Http Client (with HTTP/2 setting): HTTP 客户端: Java 11 Http 客户端(使用 HTTP/2 设置):
var httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
// ...
.build();
Problem问题
Sometimes we get GOAWAY
frames from GCM.有时我们会从 GCM 获得
GOAWAY
帧。 But java http client hides both error-code and payload for those frames (just throws some generic exception).但是java http 客户端隐藏了这些帧的错误代码和有效负载(只是抛出了一些通用异常)。 So we don't know what is causing
GOAWAY
.所以我们不知道是什么导致
GOAWAY
。
Questions问题
It's hard to tell for sure why GCM sends GOAWAY
- only the GCM team can really answer this.很难确定为什么 GCM 会发送
GOAWAY
- 只有 GCM 团队才能真正回答这个问题。 However some of the usual reasons for it are:然而,一些常见的原因是:
GOAWAY
that informs the client that no new requests should be started on that connection.GOAWAY
通知客户端不应在该连接上启动新请求来实现的。That means a server sending a GOAWAY
is not a bug, it's just something to be expected in a cloud setup.这意味着发送
GOAWAY
的服务器不是错误,这只是云设置中的预期。
The HTTP/2 specifciation provides some further information on how to handle GOAWAY
: https://tools.ietf.org/html/rfc7540#section-6.8 HTTP/2 规范提供了有关如何处理
GOAWAY
的更多信息: https://tools.ietf.org/html/rfc7540#section-6.8
Regarding handling it: Ideally your HTTP/2 client might already do that fully internally:关于处理它:理想情况下,您的 HTTP/2 客户端可能已经在内部完全做到了:
GOAWAY
frame while no request is active it should create a new connection for the next requestGOAWAY
帧,它应该为下一个请求创建一个新连接GOAWAY
frame while a request has been sent, and if that GOAWAY
frame indicates the request hasn't been processed, a new client can be created and the request retried.GOAWAY
帧,并且如果该GOAWAY
帧指示请求尚未处理,则可以创建新客户端并重试请求。 This works even if its a non-idempotent request (like a POST
), since we know the server hasn't processed the request yet.POST
),这也有效,因为我们知道服务器尚未处理该请求。 If the JDK11 client does not do that automatically, the only thing you can really do here is retry on application layer.如果 JDK11 客户端没有自动执行此操作,那么您在这里真正可以做的就是在应用层重试。
According to is there any way to handle HTTP/2 Goaway received IOException in HttpClient java?根据有什么方法可以处理 HttpClient java 中的 HTTP/2 Goaway 收到的 IOException? it seems like the client might throw an
IOException
whose message contains GOAWAY received
.似乎客户端可能会抛出一个
IOException
,其消息包含GOAWAY received
。 That might be a good signal to retry.这可能是重试的好信号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.