Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

connection keepAlive does not apply.

Đang mở
#880 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
networking

Hướng nghiên cứu

Bắt đầu bằng cách so sánh hành vi của FirebaseMessagingClient.sendSingleRequest() trong firebase-admin 6.8.0 và 8.1.0, tập trung vào ApiClientUtils.disconnectQuietly(response) và các lệnh gọi Apache HttpClient ConnectionHolder được mô tả trong báo cáo. Tái hiện vòng đời kết nối bằng chiến lược keep-alive tùy chỉnh được cung cấp và xác minh rằng các kết nối được giữ lại và tái sử dụng theo các khoảng thời gian đã cấu hình.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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;
    }
Ngôn ngữ chính
Java
Star
620
Fork
305
Merge trung bình
4 ngày 9 giờ
Pull request đã merge (30 ngày)
4

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/firebase-admin-java

Tất cả issue của firebase/firebase-admin-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.