[firebase_database, windows] Listener callbacks are delivered on a non-platform thread and crash the process
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #18656 di @SelaseKay — chiusa senza merge
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 52/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- databases, desktop-dev
Direzione di ricerca
Inizia in windows/firebase_database_plugin.cpp, concentrandoti su VL, sul listener figlio e su OnCancelInternal. Esegui la riproduzione di subscribe/unsubscribe ripetuti su Windows e traccia i cicli di vita di callback e listener. Il lavoro è completato quando gli eventi del listener raggiungono EventSink sul thread della piattaforma e la cancellazione non può liberare un listener mentre l’SDK potrebbe ancora invocarlo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug report
Which plugins are affected?
Realtime Database
Which platforms are affected?
Windows
Description
On Windows, firebase_database delivers Realtime Database listener callbacks straight from the
Firebase C++ SDK's callback thread into the Flutter EventSink. The engine reports the violation on
every event, and the process eventually dies.
[ERROR:flutter/shell/common/shell.cc(1183)] The 'plugins.flutter.io/firebase_database/query/322_...'
channel sent a message from native to Flutter on a non-platform thread. Platform channel messages
must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must
be fixed in the plugin or application code creating that channel.
In windows/firebase_database_plugin.cpp (12.5.0), the value listener and the child listener both
call events_->Success(...) from inside the SDK callback, and there is no PostTask / task-runner
hop anywhere in the file:
class VL : public firebase::database::ValueListener {
void OnValueChanged(const DataSnapshot& snapshot) override {
...
events_->Success(EncodableValue(event)); // SDK callback thread
}
flutter::EventSink<flutter::EncodableValue>* events_;
};
Separately, OnCancelInternal runs on the platform thread and deletes the listener:
if (value_listener_) {
query_.RemoveValueListener(value_listener_);
delete value_listener_; // races with an in-flight OnValueChanged
value_listener_ = nullptr;
}
so cancelling a subscription while a listen response is still being delivered frees the listener out
from under the callback thread.
Steps to reproduce
- Windows desktop app with
firebase_database. - Subscribe and unsubscribe repeatedly so that some cancels land while a listen response is in
flight (this is what screen transitions do in a long-lived session):
var i = 0;
Timer.periodic(const Duration(milliseconds: 40), (_) {
i++;
// vary the path so each listen creates a new query rather than joining an existing one
final sub = FirebaseDatabase.instance.ref('some/path/${i % 64}').onValue.listen((_) {});
Future<void>.delayed(Duration(milliseconds: i * 7 % 100), sub.cancel);
});
- The console fills with the
non-platform threaderror above, and the process dies (flutter run
printsLost connection to device.).
Expected behavior
Listener events are marshalled to the platform thread before touching the EventSink, and
cancelling a subscription does not free a listener that the SDK may still be calling into.
Actual behavior
Every event triggers the engine's non-platform-thread error, and the process terminates. Reproduced
in about 30 seconds, repeatably, on two builds.
Additional context
We hit this in production, in an app where several clients have to keep the same state in sync over
Realtime Database, so a listener stays attached for the whole session. After switching our Windows
Realtime Database usage from a third-party Dart implementation to firebase_database, crashes on
Windows increased. The same app versions on iOS showed no change.
Note this is not the same as the C++ SDK's own use-after-free
(firebase/firebase-cpp-sdk#1881, fixed in v13.11.0). We tested both:
| firebase_core / bundled firebase-cpp-sdk | firebase_database | Result |
|---|---|---|
| 4.10.0 / 13.5.0 | 12.4.2 | crashes in ~30s |
| 4.14.0 / 13.11.0 | 12.5.0 | crashes in ~30s |
Reverting our Windows Realtime Database usage to the third-party Dart implementation survived the
same loop for over 10 minutes with no thread-violation errors, so the remaining defect is in this
plugin's Windows implementation rather than in the C++ SDK.
Related, previously closed for lack of detail: #17800 (firebase_auth), #17801 (cloud_firestore).
Those report the same non-platform-thread violation on Windows in sibling plugins, so the fix may
need to be applied consistently.
Flutter doctor / versions
firebase_core4.14.0,firebase_database12.5.0- Windows Server 2025 x64
- Lingua principale
- Dart
- Stelle
- 9.3k
- Fork
- 4.1k
- Merge medio
- 1g 12h
- PR unite (30g)
- 78
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di firebase/flutterfire
-
[firebase_in_app_messaging]: Android build fails with `Could not find com.google.firebase:firebase-inappmessaging:.` since 0.10.0Forse già presa @SelaseKay l’ha presa oggi. ApertaNeeds Attention platform: android plugin: in_app_messaging reproduced type: bug
firebase/flutterfire#18872 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[firebase_messaging]: Android ANR during background service destruction — main thread blocked in releaseWakeLockForse già presa @SelaseKay l’ha presa 3 giorni fa. ApertaNeeds Attention platform: android plugin: messaging reproduced type: bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
firebase/flutterfire#18866 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
blocked: customer-response Needs Attention platform: ios plugin: messaging Stale type: bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
firebase/flutterfire#18776 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[firebase_storage] Windows native crash in upload progress callback, sink ownership and thread dispatchForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertablocked: flutter platform: windows plugin: storage reproduced type: bug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
firebase/flutterfire#18664 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[core] Decouple platform_interface from Flutter for pure-Dart webForse di nuovo libera @Lyokone l’ha presa 39 giorni fa e non c’è nessuna pull request aperta. ApertaNeeds Attention platform: all platform: web plugin: core type: enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
firebase/flutterfire#18645 · 3 commenti · 2 reazioni · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di firebase/flutterfire
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
linagora/tmail-flutter#5034 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
`printf "%o"` prints decimalAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
fable-compiler/Fable#5157 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
bannzai/medicalarm#430 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
fossasia/badgemagic-app#2016 ·
I maintainer di solito rispondono entro 1 giorno
-
area-vm
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
dart-lang/sdk#64727 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni