FCM sends 502 Bad Gateway Error

2,374 views
Skip to first unread message

Udit Agrawal

unread,
Jul 8, 2021, 7:17:35 AM7/8/21
to Firebase Google Group
Hi,

We are using HTTP v1 API for sending push request to FCM. So basically i am doing some load testing around it, the actual server is loaded on google cloud. So here's my setup jmeter -> GCP -> firebase.

When i send in concurrent requests suddenly i started seeing in jmeter probably coming along from FCM.

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>502 Server Error</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Server Error</h1>
<h2>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.</h2>
<h2></h2>
</body></html>

This is a sample test message body that i sent in to FCM 
{
"message":
{
"topic":"MY_TOKEN",
"notification":
{
"title":"Hello",
"body":"This is a text message!"
}
}
}

and this is the response that i get from them - 
{
  "name": "projects/apnp-dev/messages/1831093353292721835"
}

Can someone please help me out on how to tackle this issue ??

Thanks!! Much appreciated!!

Hafiz Saad Iftikhar

unread,
Jul 8, 2021, 10:00:24 AM7/8/21
to Firebase Google Group
You need to use "to" instead of message 
Try this. I hope it will solve your problem

For more information, Click here

Udit Agrawal

unread,
Jul 8, 2021, 10:40:25 AM7/8/21
to fireba...@googlegroups.com
Are you talking about the message body that I am sending ?? I use this - 
{
"message":
{
"topic":"MY_TOKEN",
"notification":
{
"title":"Hello",
"body":"This is a text message!"
}
}
}

What change are you proposing? I am a bit confused. Please suggest. Thanks!!

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/e0d18b1e-3840-47ce-98f9-87f05b8a50f1n%40googlegroups.com.

Arthur Thompson

unread,
Jul 8, 2021, 11:29:41 AM7/8/21
to Firebase Google Group
If you are receiving a 5xx error of any kind then you should file a support case. The message payload looks correct.

You mentioned that you are doing load testing. I'm very confident that FCM can handle the load you are sending so I don't think load testing FCM itself is necessary but either way you should not be getting 500s.

Udit Agrawal

unread,
Jul 8, 2021, 11:57:40 AM7/8/21
to fireba...@googlegroups.com
Yes I'm sure FCM can handle the requests but it doesn't look good when it returns back a 502 when we fire parallel requests to it. It should be able to handle it.

On the other hand should i be implementing some exponential backoff algorithm sort of thing, something like if my app server is getting a 502 i should be retrying exponentially. Will this help ? Ideally i shouldn't be.

Please let me know. Thanks!!

I will file a case with firebase in the mean time.

Arthur Thompson

unread,
Jul 8, 2021, 12:05:48 PM7/8/21
to Firebase Google Group
As the message says "try again in 30 seconds" so I would do that, seems reasonable to do some type of backoff.

Hafiz Saad Iftikhar

unread,
Jul 9, 2021, 5:30:27 AM7/9/21
to Firebase Google Group
Sorry for the late response. Try like this
If you are sending notifications on a topic base you should use the topic name that the user subscribed to.
If you're sending on token base then you need to use the token instead of "Topic_Name"

For Topic
"to":
{
"topic":"Topic_Name",
"notification":
{
"title":"Hello",
"body":"This is a text message!"
}
}
}

For Token
"to":
{
"token":"FCM_Token",

Udit Agrawal

unread,
Jul 12, 2021, 4:59:45 AM7/12/21
to Firebase Google Group
No... this doesn't work. Firebase gives me 400 Bad Request in this case.

Although i did implement a retry mechanism wherein the failure rate has reduced a lot but still certain request to FCM failed upon retrying with error - 

SEVERE: Unhandled exception
java.lang.IllegalStateException: Response is closed
at io.vertx.core.http.impl.HttpServerResponseImpl.checkValid(HttpServerResponseImpl.java:576)
at io.vertx.core.http.impl.HttpServerResponseImpl.end(HttpServerResponseImpl.java:324)
at io.vertx.core.http.impl.HttpServerResponseImpl.end(HttpServerResponseImpl.java:367)
at com.avaya.apnsproxy.http.HttpProxy.handleApnsRequestException(HttpProxy.java:337)
at com.avaya.apnsproxy.http.HttpProxy.lambda$retryRequest$1(HttpProxy.java:77)
at io.vertx.core.http.impl.HttpClientRequestBase.handleException(HttpClientRequestBase.java:139)
at io.vertx.core.http.impl.HttpClientRequestBase.doHandleResponse(HttpClientRequestBase.java:177)
at io.vertx.core.http.impl.HttpClientRequestBase.checkHandleResponse(HttpClientRequestBase.java:162)
at io.vertx.core.http.impl.HttpClientRequestBase.handleResponse(HttpClientRequestBase.java:146)
at io.vertx.core.http.impl.Http1xClientConnection.handleResponseBegin(Http1xClientConnection.java:624)
at io.vertx.core.http.impl.Http1xClientConnection.handleHttpMessage(Http1xClientConnection.java:594)
at io.vertx.core.http.impl.Http1xClientConnection.handleMessage(Http1xClientConnection.java:560)
at io.vertx.core.net.impl.ConnectionBase.handleRead(ConnectionBase.java:397)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:43)
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:188)
at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:174)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:426)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1429)
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1199)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1243)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)

Can anybody point me why is this happening ?

Reply all
Reply to author
Forward
0 new messages