[firebase_messaging]: Android: a burst of background messages starts a FlutterEngine per service start, and can lose all of them
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Read FlutterFirebaseMessagingBackgroundExecutor.java around line 140 and trace how startBackgroundIsolate() assigns the engine before the queued callback runs. Reproduce with a burst of background data messages on Android, then check that only one engine is created and every queued message is handled. The issue reports a one-line fix and a successful 12-message run, though it does not name a test file.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Messaging
Which platforms are affected?
Android
Description
When several data messages reach an app that isn't running (a device switched on, or back online, after missing a few), FlutterFirebaseMessagingBackgroundExecutor creates a background FlutterEngine for every FlutterFirebaseMessagingBackgroundService start that lands before the first engine exists, instead of one.
Expected: one background engine, and every message handled.
Actual: one engine per early service start. On a profile build, 12 messages held while the device was off, then boot: 6 × Creating background FlutterEngine instance. and 6 × FlutterFirebaseMessagingBackgroundService started! in one process. On a debug build, 22 held messages: 22 engines, then the low-memory killer, and no notification shown.
Cause: onCreate calls startBackgroundIsolate(), whose guard is if (backgroundFlutterEngine != null) return;. But the engine is only assigned inside the callback that method posts to the main looper after ensureInitializationCompleteAsync. Every service start before then posts another callback. The callback checks only isNotRunning(), which stays true until Dart sends MessagingBackground#initialized, so each one creates a new engine, overwrites backgroundFlutterEngine and backgroundChannel, and starts another isolate. The queued intents drain only in onInitialized. Their work was already completed, so if the process dies first (memory pressure from N engines) they are lost.
Fix (FlutterFirebaseMessagingBackgroundExecutor.java, L140 on 16.7.0 and on main at 90c22c8dd9):
- if (isNotRunning()) {
+ if (isNotRunning() && backgroundFlutterEngine == null) {
onCreate, the posted runnable and its callback all run on the main looper, so once the first callback assigns the engine, every later one skips. With that change, the same 12-message boot burst makes one engine and shows all 12 notifications.
Reproducing the issue
- Register a handler with
FirebaseMessaging.onBackgroundMessage. - Power the device off.
- Send ≥10 high-priority, data-only messages to it.
- Boot the device without opening the app.
- Count
Creating background FlutterEngine instance.in logcat: one per early service start, not one.
A profile or release build shows the duplicate engines cleanly. On a debug build the first engine's kernel load on the main thread (7–10 s) can also trip a background ANR on the pending FCM broadcast, which is a separate, debug-only effect.
Firebase Core version
4.15.0
Flutter Version
3.47.7
Relevant Log Output
# Profile build, 12 held data messages, device booted without opening the app (one process):
I FLTFireBGExecutor: Creating background FlutterEngine instance. (×6)
I FLTFireMsgService: FlutterFirebaseMessagingBackgroundService started! (×6)
# The same burst with the one-line fix:
I FLTFireBGExecutor: Creating background FlutterEngine instance. (×1)
I FLTFireMsgService: FlutterFirebaseMessagingBackgroundService started! (×1)
Flutter dependencies
firebase_messaging 16.7.0, firebase_core 4.15.0.
Additional context and comments
- Versions: firebase_messaging 16.7.0 and
mainat 90c22c8dd9. Earlier 16.x releases (checked: 16.4.2, 16.4.3, 16.6.0) have the sameisNotRunning()-only check in the callback. - Tested on an Android 16 emulator.
- We're carrying the one-line change above as a build-time patch until a fix ships, and we're happy to open a PR with it if that helps.
- Ngôn ngữ chính
- Dart
- Star
- 9.3k
- Fork
- 4.1k
- Merge trung bình
- 2 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 41
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase C++ SDK (13.13.0 → 14.0.0)Có thể đã có người làm @SelaseKay đã nhận hôm nay. Đang mởNeeds Attention plugin: core type: enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 18/100
firebase/flutterfire#18798 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[firebase_auth]: authStateChanges() never emits null when the user is force-signed-out before the stream is listened to (iOS, macOS, Android)Có thể đã có người làm @JulianPscheid đã nhận hôm nay. Đang mởNeeds Attention platform: android platform: ios platform: macos plugin: auth type: bug
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 15/100
firebase/flutterfire#18796 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs Attention platform: ios plugin: messaging type: bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
firebase/flutterfire#18793 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[firebase_core] Firebase.initializeApp with demoProjectId crashes on iOS with SIGABRT (FIRInstallations validateAPIKey) - Follow-up to locked #17788Có thể đã có người làm @SelaseKay đã nhận 1 ngày trước. Đang mởNeeds Attention platform: ios plugin: core reproduced type: bug type: crash
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 22/100
firebase/flutterfire#18790 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
blocked: customer-response Needs Attention platform: ios plugin: messaging type: bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
firebase/flutterfire#18776 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của firebase/flutterfire
Issue tương tự
-
coverage 1.16.0: format_coverage fails on the `{}` that `dart test --coverage` writes for fully skipped suitesCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
fyi-ecosystem platform-ios team-ios
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
flutter/flutter#194348 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
djazairdev/wilayas#22 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
rajput-hemant/calculator#199 · 3 bình luận · 1 reaction ·