Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

connection keepAlive does not apply.

オープン
#880 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
java
領域
networking

調査の方向性

まず、firebase-admin 6.8.0 と 8.1.0 における FirebaseMessagingClient.sendSingleRequest() の動作を比較し、ApiClientUtils.disconnectQuietly(response) と、レポートで説明されている Apache HttpClient ConnectionHolder の呼び出しに注目します。提供されたカスタム keep-alive 戦略を使用して接続のライフサイクルを再現し、設定された期間に従って接続が保持および再利用されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

needs-triage
[REQUIRED] Step 2: Describe your environment
  • Operating System version: linux
  • Firebase SDK version: firebase-admin-8.1.0.jar
  • Library version: 8.1.0.jar
  • Firebase Product: Cloud Messaging (auth, database, storage, etc)
[REQUIRED] Step 3: Describe the problem

We confirmed that keepAlive is applied when using firebase-admin version 6.8.0.
However, after upgrading to firebase-admin 8.1.0, keepAlive is not applied and the connection is immediately disconnected.

Steps to reproduce:

firebase-admin 6.8.0 FirebaseMessagingClient.sendSingleRequest()
image
(apache httpclient-4.5.11) ConnectionHolder.releaseConnection() is called due to line 129.
At this time, this.released changes from false to true.
After that, ApiClientUtils.disconnectQuietly(response) -> (apache httpclient-4.5.11) ConnectionHolder.abortConnection() on line 132 is called, but the connection is not disconnected because ConnectionHolder.released = true.
image
image

However, in firebase-admin 8.1.0, ConnectionHolder.releaseConnection() is not called, but ConnectionHolder.abortConnection() is called, so the connection is disconnected.
image

What happened? How can we make the problem occur?
Establishing connections is expensive. Therefore, recycling connections for a certain period of time can help improve performance. According to what I have checked, the code of the latest version, 9.2.0, is also the same.

Relevant Code:
private FirebaseMessaging initializeFirebaseMessaging()
        throws IOException {
        CloseableHttpClient httpClient = newHttpClient(proxyHost, proxyPort);

        HttpTransport httpTransport = new ApacheHttpTransport(httpClient);

        FirebaseOptions options = FirebaseOptions.builder()
// need credentials etc
                                                 .setHttpTransport(httpTransport)
                                                 .build();

        FirebaseApp.initializeApp(options);
        return FirebaseMessaging.getInstance();
    }

private CloseableHttpClient newHttpClient(String proxyHost, int proxyPort) {
        HttpClientBuilder httpClientBuilder = ApacheHttpTransport.newDefaultHttpClientBuilder()
                                                                 .evictExpiredConnections()
                                                                 .setKeepAliveStrategy(
                                                                     new CustomConnectionKeepAliveStrategy(
                                                                         TimeUnit.MINUTES.toMillis(3)))
                                                                 .setConnectionTimeToLive(10, TimeUnit.MINUTES)
                                                                 .setDefaultRequestConfig(requestConfig())
                                                                 .disableCookieManagement();
        return httpClientBuilder.build();
    }

public class CustomConnectionKeepAliveStrategy implements ConnectionKeepAliveStrategy {

    public static final CustomConnectionKeepAliveStrategy INSTANCE =
        new CustomConnectionKeepAliveStrategy(TimeUnit.SECONDS.toMillis(50),
            DefaultConnectionKeepAliveStrategy.INSTANCE);

    public static final ConnectionKeepAliveStrategy NO_KEEPALIVE = (response, context) -> 0;

    private static final long KEEP_ALIVE_SAFE_GAP = 500L;
    private final ConnectionKeepAliveStrategy defaultConnectionKeepAliveStrategy;
    private final long defaultKeepAliveTimeoutInMillis;

    public CustomConnectionKeepAliveStrategy(long defaultKeepAliveTimeoutInMillis) {
        this(defaultKeepAliveTimeoutInMillis, DefaultConnectionKeepAliveStrategy.INSTANCE);
    }

    public CustomConnectionKeepAliveStrategy(long defaultKeepAliveTimeoutInMillis,
        ConnectionKeepAliveStrategy defaultConnectionKeepAliveStrategy) {
        Args.notNegative(defaultKeepAliveTimeoutInMillis, "defaultKeepAliveTimeoutInMillis");
        Args.notNull(defaultConnectionKeepAliveStrategy, "defaultConnectionKeepAliveStrategy");
        this.defaultKeepAliveTimeoutInMillis = defaultKeepAliveTimeoutInMillis;
        this.defaultConnectionKeepAliveStrategy = defaultConnectionKeepAliveStrategy;
    }

    public static long adjustKeepAliveTimeout(long keepAliveTimeoutInMillis) {
        return Math.max(0L, (keepAliveTimeoutInMillis - KEEP_ALIVE_SAFE_GAP));
    }

    @Override
    public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
        long keepAliveDuration = defaultConnectionKeepAliveStrategy.getKeepAliveDuration(response, context);
        if (keepAliveDuration == -1L) {
            return defaultKeepAliveTimeoutInMillis;
        }
        if (keepAliveDuration > 0L) {
            return adjustKeepAliveTimeout(keepAliveDuration);
        }
        return keepAliveDuration;
    }
主要言語
Java
スター
620
フォーク
305
平均マージ
4日 9時間
マージ済み PR(30日)
4

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/firebase-admin-java のほかの issue

firebase/firebase-admin-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。