You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"cloud_firestore EventChannel callbacks fire from wrong thread, engine fast-fails." The fix pattern is the same opt-in flag approach, applied to Firestore's channels. #18226
[cloud_firestore] Windows: FAST_FAIL_INVALID_ARG (0xc0000409) from EventChannel callback on wrong thread (same root cause as #18210 / closed PR #18223)
This is the cloud_firestore manifestation of the same Windows plugin
threading bug already reported for firebase_auth. The Windows firebase_firestore_plugin dispatches EventChannel traffic (snapshot
listeners, metadata streams) from a native background thread. The Flutter
Windows engine requires platform channel traffic on the platform thread and
calls fml::KillProcess → __fastfail(FAST_FAIL_INVALID_ARG) when that
contract is violated, terminating the host process with 0xc0000409
(STATUS_STACK_BUFFER_OVERRUN, subcode 0x5).
PR #18223 only covers the firebase_authid-tokenEventChannel. After
applying that workaround conceptually (skipping the auth id-token channel), cloud_firestore still crashes because Firestore opens its own
EventChannels (snapshot subscriptions, query metadata) that exhibit the same
wrong-thread dispatch. This issue requests the equivalent treatment for cloud_firestore.
Steps to reproduce
flutter create an app, target Windows desktop.
Add firebase_core, firebase_auth, cloud_firestore (versions in env block).
Configure firebase_options.dart. (No first-class Windows FirebaseOptions
exists for our project; on Windows we pass the Web app options to Firebase.initializeApp(...). This is the documented Windows pattern today.)
Process is terminated immediately with 0xc0000409.
A minimal example:
import'package:flutter/material.dart';
import'package:firebase_core/firebase_core.dart';
import'package:firebase_auth/firebase_auth.dart';
import'package:cloud_firestore/cloud_firestore.dart';
import'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
awaitFirebase.initializeApp(
options:DefaultFirebaseOptions.web, // Web options used on Windows
);
awaitFirebaseAuth.instance.signInWithEmailAndPassword(
email:'test@example.com',
password:'...',
);
// Crashes here on Windows desktop with 0xc0000409.final snap =awaitFirebaseFirestore.instance
.collection('test')
.limit(1)
.get();
debugPrint('docs: ${snap.size}');
runApp(constMaterialApp(home:Scaffold(body:Center(child:Text('ok')))));
}
Expected behavior
The Firestore call returns normally or throws a catchable FirebaseException. The host process must not be terminated by an unhandled
fast-fail.
Actual behavior
Exception code: 0xc0000409 (STATUS_STACK_BUFFER_OVERRUN)
Subcode: 0x5 (FAST_FAIL_INVALID_ARG)
Faulting IP: patient_manager+0xbe15 -> cd 29 int 29h
WinDbg !analyze -v (relevant frames, with the same shape as the engine fml::KillProcess → PlatformMessageHandlerStandard::InvokeHandler → IncomingMessageDispatcher::HandleMessage → plugin-callback-from-wrong-thread
pattern documented in PR #18223):
The "nearest export" symbol (CloudFirestorePluginCApiRegisterWithRegistrar)
is just the closest symbol the debugger could resolve — actual frames are
unsymbolicated cloud_firestore plugin code (no PDB shipped).
The only mitigation that prevents the crash in our app is removing every cloud_firestore call from the Windows code path. We replaced custom-claims
hydration with direct base64url decode of user.getIdToken(false) and
short-circuited every Firestore read/write on Platform.isWindows. With cloud_firestore not invoked at all, the app is stable.
Add an opt-in static flag on FirebaseFirestorePlatform (or an analogous
location) to skip the Windows snapshot/metadata EventChannel registration
the same way PR #18223 proposed for firebase_auth.id-token. Apps that don't
need live snapshots() streams on Windows could opt in and use imperative get() calls only. Long-term fix is still flutter/flutter#134346,
but an explicit Dart-only escape hatch unblocks every Windows user today.
[cloud_firestore] Windows: FAST_FAIL_INVALID_ARG (0xc0000409) from EventChannel callback on wrong thread (same root cause as #18210 / closed PR #18223)
Bug description
This is the
cloud_firestoremanifestation of the same Windows pluginthreading bug already reported for
firebase_auth. The Windowsfirebase_firestore_plugindispatchesEventChanneltraffic (snapshotlisteners, metadata streams) from a native background thread. The Flutter
Windows engine requires platform channel traffic on the platform thread and
calls
fml::KillProcess→__fastfail(FAST_FAIL_INVALID_ARG)when thatcontract is violated, terminating the host process with
0xc0000409(
STATUS_STACK_BUFFER_OVERRUN, subcode0x5).Related work:
flutter/flutter#134346 — Make Windows plugin APIs thread-safe (open since Sep 2023, P2)
firebase_authversion of this crash:#18210
firebase_auth:#18223
#13340,
#16888,
#17800,
#11933
PR #18223 only covers the
firebase_authid-tokenEventChannel. Afterapplying that workaround conceptually (skipping the auth id-token channel),
cloud_firestorestill crashes because Firestore opens its ownEventChannels (snapshot subscriptions, query metadata) that exhibit the same
wrong-thread dispatch. This issue requests the equivalent treatment for
cloud_firestore.Steps to reproduce
flutter createan app, target Windows desktop.firebase_core,firebase_auth,cloud_firestore(versions in env block).firebase_options.dart. (No first-class WindowsFirebaseOptionsexists for our project; on Windows we pass the Web app options to
Firebase.initializeApp(...). This is the documented Windows pattern today.)0xc0000409.A minimal example:
Expected behavior
The Firestore call returns normally or throws a catchable
FirebaseException. The host process must not be terminated by an unhandledfast-fail.
Actual behavior
WinDbg
!analyze -v(relevant frames, with the same shape as the enginefml::KillProcess→PlatformMessageHandlerStandard::InvokeHandler→IncomingMessageDispatcher::HandleMessage→ plugin-callback-from-wrong-threadpattern documented in PR #18223):
Notes:
CloudFirestorePluginCApiRegisterWithRegistrar)is just the closest symbol the debugger could resolve — actual frames are
unsymbolicated
cloud_firestoreplugin code (no PDB shipped).matching the PR fix(auth, windows): add opt-in flag to skip id-token EventChannel (FAST_FAIL_INVALID_ARG workaround) #18223 description of plugin event callbacks invoked on a
background native thread then re-entering the engine's incoming-message
dispatcher on the wrong thread.
__fastfail(5)here is emitted by the Flutter engine'sfml::KillProcesswhen its thread-affinity assertion trips — same termination path PR fix(auth, windows): add opt-in flag to skip id-token EventChannel (FAST_FAIL_INVALID_ARG workaround) #18223
identifies for
firebase_auth.What we already tried (Dart-side mitigations that do NOT help)
Settings(persistenceEnabled: false),host:overrides ✕disableNetwork()before any read ✕get,snapshots(),doc().get()) ✕Future.microtask,addPostFrameCallback,Future.delayed,runZonedGuarded, customBinaryMessenger✕(consistent with PR fix(auth, windows): add opt-in flag to skip id-token EventChannel (FAST_FAIL_INVALID_ARG workaround) #18223's analysis: every Dart-side mitigation runs
after the native side has already dispatched from the wrong thread)
The only mitigation that prevents the crash in our app is removing every
cloud_firestorecall from the Windows code path. We replaced custom-claimshydration with direct base64url decode of
user.getIdToken(false)andshort-circuited every Firestore read/write on
Platform.isWindows. Withcloud_firestorenot invoked at all, the app is stable.Proposed fix (mirroring PR #18223 for Firestore)
Add an opt-in static flag on
FirebaseFirestorePlatform(or an analogouslocation) to skip the Windows snapshot/metadata
EventChannelregistrationthe same way PR #18223 proposed for
firebase_auth.id-token. Apps that don'tneed live
snapshots()streams on Windows could opt in and use imperativeget()calls only. Long-term fix is stillflutter/flutter#134346,
but an explicit Dart-only escape hatch unblocks every Windows user today.
Environment
flutter doctor -vWindows toolchain:Plugin versions (
pubspec.lock):cloud_firestore3ac242332166ae5037bd87bc343744bb96d88d7b13f791492b00958ce5cc6c63cloud_firestore_platform_interface1bd08b736e1015e8bf5448f5ef67b2087a2380c2c1c7972f8403c1c7b41f5359firebase_cored5a94b884dcb1e6d3430298e94bfe002238094cdfd5e29202d536ee2120f9158firebase_authb12cb1e2e87797d27e0041100b73ebf890dbafcff2e7e991d4593f5e8e309808firebase_storage825a5a64addc66b57a2e793b5e40343d1364e8b5a2a0d7e6cfc116ae9c021fbdcloud_functions036aa4f3b880935bda48fd6ab516e0f11686c328a46313226b9cbad9220b4c59firebase_messaginge5c93e8e7a9b0513f94bb684d2cf100e32e7dcdf2949574386b1955fc9a9b96aBuild mode: debug and release both crash identically.
Crash artifacts
!analyze -voutput: included above.