Skip to content

HTTP 2 in FCM

Jonathan Edey edited this page Apr 22, 2025 · 1 revision

Session Errors

Catching Session Errors

Starting in v13.3.0, session errors can be thrown from sendEach() and sendEachMulticast() methods. Since session errors are not attributed to one specific request and may require a new session connection to be made, they can affect every request that is to be sent on that session causing them to fail.

To better manage these errors we have provided a FirebaseMessagingSessionError which outlines the error responsible for the session closure along with the pending BatchResponse of the messages that were expected to be sent in order to identify successful and failed requests.

return messaging.sendEach(messages).then((response: BatchResponse) => {
  // Handle BatchResponse
  ...
}).catch(async (error: FirebaseMessagingSessionError) => {
  // Handle session error
  ...

  // Access pending BatchResponse
  await error.pendingBatchResponse.then((response: BatchResponse) => {
    ...
  });
});

Handling Session Errors

Currently, the SDK does not support a persistent session across multiple sendEach() and sendEachMulticast() calls. As a result most session errors can be resolved by making a new sendEach() call or managing quota limits. However, some errors like ERR_HTTP2_PROTOCOL_ERROR or ECONNREFUSED would suggest an issue with the network configuration in the developers environment. These errors should be resolved first before making new calls to sendEach() or sendEachMulticast().

HTTP Agent

Currently, the SDK does not support setting a http.Agent on a HTTP/2 Connection and as a result http.Agent is ignored when sending FCM messages using the HTTP/2 transport layer.

Using Legacy HTTP/1.1

In the event of issues with the new HTTP/2 transport layer, developers can fall back to the legacy HTTP/1.1 logic by using the enableLegacyHttpTransport() method. This method, although marked deprecated, is intended to remain until the HTTP/2 transport implementation reaches the same stability as the legacy HTTP/1.1 implementation.

const messaging = getMessaging(app);
messaging.enableLegacyHttpTransport();
messaging.sendEach(messages);
Clone this wiki locally