Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirebaseMessagingException: Connection refused on server #873

Open
neewaz opened this issue Oct 31, 2023 · 4 comments
Open

FirebaseMessagingException: Connection refused on server #873

neewaz opened this issue Oct 31, 2023 · 4 comments

Comments

@neewaz
Copy link

neewaz commented Oct 31, 2023

Environment:

  • Firebase SDK version: 9.2.0
  • Library version:
  • Firebase Product: Firebase cloud messaging (FCM)

Problem:

I am having a problem using firebase admin sdk to send push notification from a java based web application.
When i run the code from localhost, everything is working and i was initialize the firebase app and send message.
But it is not working on the server.
I am getting following error.

Log:

10:40:24 com.google.firebase.messaging.FirebaseMessagingException: Unknown error while making a remote service call: Connection refused (Connection refused)
10:40:24 at com.google.firebase.messaging.FirebaseMessagingException.withMessagingErrorCode(FirebaseMessagingException.java:51)
10:40:24 at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1306)
10:40:24 at com.google.firebase.messaging.FirebaseMessagingClientImpl$MessagingErrorHandler.createException(FirebaseMessagingClientImpl.java:293)
10:40:24 at com.google.firebase.messaging.FirebaseMessagingClientImpl$MessagingErrorHandler.createException(FirebaseMessagingClientImpl.java:282)
10:40:24 at com.google.firebase.internal.AbstractHttpErrorHandler.handleIOException(AbstractHttpErrorHandler.java:63)
10:40:24 at com.google.firebase.internal.ErrorHandlingHttpClient.send(ErrorHandlingHttpClient.java:110)
10:40:24 at com.google.firebase.internal.ErrorHandlingHttpClient.sendAndParse(ErrorHandlingHttpClient.java:72)
10:40:24 at com.google.firebase.messaging.FirebaseMessagingClientImpl.sendSingleRequest(FirebaseMessagingClientImpl.java:127)
10:40:24 at com.google.firebase.messaging.FirebaseMessagingClientImpl.send(FirebaseMessagingClientImpl.java:113)
10:40:24 at com.google.firebase.messaging.FirebaseMessaging$1.execute(FirebaseMessaging.java:141)
10:40:24 at com.google.firebase.messaging.FirebaseMessaging$1.execute(FirebaseMessaging.java:138)
10:40:24 at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
10:40:24 at com.google.firebase.messaging.FirebaseMessaging.send(FirebaseMessaging.java:108)
10:40:24 at com.google.firebase.messaging.FirebaseMessaging.send(FirebaseMessaging.java:90)
10:40:24 at firebase.actions.JA_SendFirebaseMessage.sendFCMMessage(JA_SendFirebaseMessage.java:91)
10:40:24 at firebase.actions.JA_SendFirebaseMessage.executeAction(JA_SendFirebaseMessage.java:57)
10:40:24 at firebase.actions.JA_SendFirebaseMessage.executeAction(JA_SendFirebaseMessage.java:30)
10:40:24 at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:58)
10:40:24 at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:71)
10:40:24 at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:48)
10:40:24 at com.mendix.core.actionmanagement.internal.InternalCoreAction.call(InternalCoreAction.java:57)
10:40:24 at com.mendix.basis.actionmanagement.ActionManager.$anonfun$executeSync$2(ActionManager.scala:104)
10:40:24 at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20)
10:40:24 at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:103)
10:40:24 at com.mendix.basis.actionmanagement.UserActionCallBuilderImpl.execute(UserActionCallBuilderImpl.scala:57)
10:40:24 at com.mendix.modules.microflowengine.actions.actioncall.ForegroundJavaAction.doExecute(ForegroundJavaAction.scala:35)
10:40:24 at com.mendix.modules.microflowengine.actions.actioncall.ForegroundJavaAction.doExecute(ForegroundJavaAction.scala:11)
10:40:24 at com.mendix.modules.microflowengine.actions.actioncall.JavaAction.execute(JavaAction.scala:38)
10:40:24 at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.$anonfun$execute$1(MicroflowObject.scala:32)
10:40:24 at scala.Option.flatMap(Option.scala:283)
10:40:24 at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.scala:29)
10:40:24 at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.scala:176)
10:40:24 at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.scala:116)
10:40:24 at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:58)
10:40:24 at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:71)
10:40:24 at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:48)
10:40:24 at com.mendix.core.actionmanagement.internal.InternalCoreAction.call(InternalCoreAction.java:57)
10:40:24 at com.mendix.basis.actionmanagement.ActionManager.$anonfun$executeSync$2(ActionManager.scala:104)
10:40:24 at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20)
10:40:24 at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:103)
10:40:24 at com.mendix.basis.actionmanagement.MicroflowCallBuilderImpl.execute(MicroflowCallBuilderImpl.scala:62)
10:40:24 at com.mendix.webui.actions.client.MicroflowRuntimeOperationExecutor.runMicroflow(MicroflowRuntimeOperationExecutor.scala:97)
10:40:24 at com.mendix.webui.actions.client.MicroflowRuntimeOperationExecutor.$anonfun$apply$5(MicroflowRuntimeOperationExecutor.scala:57)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction$Helpers$.$anonfun$liftEither$1(RegularClientAction.scala:30)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.$anonfun$apply$4(RegularClientAction.scala:56)
10:40:24 at com.mendix.webui.requesthandling.helpers.StateHandling.withState(StateHandling.scala:46)
10:40:24 at com.mendix.webui.requesthandling.helpers.StateHandling.withState$(StateHandling.scala:43)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.withState(RegularClientAction.scala:46)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.apply(RegularClientAction.scala:54)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.apply(RegularClientAction.scala:46)
10:40:24 at com.mendix.webui.actions.client.MicroflowRuntimeOperationExecutor.apply(MicroflowRuntimeOperationExecutor.scala:58)
10:40:24 at com.mendix.webui.actions.client.RuntimeOperationAction.$anonfun$apply$1(RuntimeOperationAction.scala:49)
10:40:24 at scala.util.Either.flatMap(Either.scala:352)
10:40:24 at com.mendix.webui.actions.client.RuntimeOperationAction.apply(RuntimeOperationAction.scala:33)
10:40:24 at com.mendix.webui.actions.client.RuntimeOperationAction.apply(RuntimeOperationAction.scala:22)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction$Helpers$.$anonfun$liftEither$1(RegularClientAction.scala:30)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$3(RegularClientAction.scala:120)
10:40:24 at scala.util.Try$.apply(Try.scala:210)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2(RegularClientAction.scala:120)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2$adapted(RegularClientAction.scala:118)
10:40:24 at com.mendix.webui.requesthandling.helpers.ContextHandling.$anonfun$inContext$7(ContextHandling.scala:59)
10:40:24 at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
10:40:24 at com.mendix.basis.actionmanagement.ActionMonitoring$.$anonfun$monitor$1(ActionMonitoring.scala:52)
10:40:24 at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20)
10:40:24 at com.mendix.basis.actionmanagement.ActionMonitoring$.monitor(ActionMonitoring.scala:52)
10:40:24 at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:59)
10:40:24 at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:33)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:94)
10:40:24 at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:30)
10:40:24 at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:22)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:94)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$1(RegularClientAction.scala:118)
10:40:24 at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
10:40:24 at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest(ProfileHandling.scala:14)
10:40:24 at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest$(ProfileHandling.scala:10)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.profileRequest(RegularClientAction.scala:94)
10:40:24 at com.mendix.webui.actions.client.RegularClientAction.execute(RegularClientAction.scala:115)
10:40:24 at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:96)
10:40:24 at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:69)
10:40:24 at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:37)
10:40:24 at com.mendix.external.connector.MxRuntimeConnector.$anonfun$processRequest$1(MxRuntimeConnector.scala:54)
10:40:24 at com.mendix.external.connector.MxRuntimeConnector.$anonfun$processRequest$1$adapted(MxRuntimeConnector.scala:54)
10:40:24 at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20)
10:40:24 at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.scala:54)
10:40:24 at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.scala:218)
10:40:24 at com.mendix.m2ee.appcontainer.server.handler.RuntimeServlet.service(RuntimeServlet.scala:40)
10:40:24 at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
10:40:24 at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
10:40:24 at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
10:40:24 at org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:170)
10:40:24 at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
10:40:24 at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
10:40:24 at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
10:40:24 at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
10:40:24 at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1570)
10:40:24 at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
10:40:24 at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1384)
10:40:24 at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
10:40:24 at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
10:40:24 at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1543)
10:40:24 at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
10:40:24 at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
10:40:24 at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
10:40:24 at org.eclipse.jetty.server.Server.handle(Server.java:563)
10:40:24 at org.eclipse.jetty.server.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1598)
10:40:24 at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753)
10:40:24 at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501)
10:40:24 at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
10:40:24 at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
10:40:24 at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
10:40:24 at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
10:40:24 at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:421)
10:40:24 at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390)
10:40:24 at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277)
10:40:24 at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:199)
10:40:24 at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
10:40:24 at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
10:40:24 at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
10:40:24 at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
10:40:24 at java.base/java.lang.Thread.run(Unknown Source)
10:40:24 Caused by: java.net.ConnectException: Connection refused (Connection refused)
10:40:24 at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
10:40:24 at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
10:40:24 at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
10:40:24 at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
10:40:24 at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
10:40:24 at java.base/java.net.Socket.connect(Unknown Source)
10:40:24 at java.base/sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
10:40:24 at java.base/sun.net.NetworkClient.doConnect(Unknown Source)
10:40:24 at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
10:40:24 at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.https.HttpsClient.(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
10:40:24 at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
10:40:24 at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:113)
10:40:24 at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:84)
10:40:24 at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1012)
10:40:24 at com.google.firebase.internal.ErrorHandlingHttpClient.send(ErrorHandlingHttpClient.java:96)
10:40:24 ... 115 more

Code:

Initialising firebase app

if(FirebaseApp.getApps().isEmpty()) { FirebaseOptions options = FirebaseOptions.builder().setCredentials(GoogleCredentials.fromStream(serviceAccountKeyFileStream)).build(); try { FirebaseApp.initializeApp(options); } catch (Exception e) { logger.info("FirebaseApp initialised failed."); throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Initialising FirebaseApp failed.\n"+e); } }

Sending message

`Message message = Message.builder()
.putData("title", firebaseMessage.getTitle())
.putData("body", firebaseMessage.getBody())
.putData("url", firebaseMessage.getUrl())
.setToken(firebaseMessage.getToken())
.build();

var messagingInstance = FirebaseMessaging.getInstance();
var response = messagingInstance.send(message);`

@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@bashbers
Copy link

bashbers commented Nov 7, 2023

is your server able to directly access the firebase servers or is there some sort of enterprise gateway inbetween your server and firebase actively blocking any non-whitelisted sources?

private static final String FCM_URL = "https://fcm.googleapis.com/v1/projects/%s/messages:send";
As you can see here, it's hardcoded to send messages to fcm.googleapis.com.

If you want / are able to wait for the suggested PR as written here: #802 (comment), otherwise you could copy my linked reflection snippet to change this behaviour.

@neewaz
Copy link
Author

neewaz commented Nov 8, 2023

My server is a Sandbox there is enterprise getaway in between. I will tryout the snippet you send. But I think the server Firewall could also be causing the problem and I need to whitelist firebase endpoints and ports to be able to communicate. Is there any documentation or link where I can find the list of links/IP-Addresses and ports that should be whitelisted on my server?

@lee-dongyeop
Copy link

Hello, I encountered the same symptom error in the same situation.
Unknown error while making a remote service call: Connection reset

I am using API Gateway, but not all message transmission processes produce errors and often occur.
Therefore, it doesn't seem to be a reason for blocking the firewall of API Gateway.

When I looked up the token of the user who had that error, it turned out to be the case of Android, can you tell me what the problem is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants