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
{{ message }}
Repository navigation
Using a single-instance lock for hot restart in debug mode will cause the application to become unresponsive. #76
We tested hot restart (Shift+R / R in flutter run -d windows) on Windows 11 with both flutter_single_instance_example and ZeroBit-Player (with if (kDebugMode) return; removed, using nativeapi_flutter: 0.6.3), and consecutive hot restarts completed in <1s with the window remaining responsive (RequestSingleInstanceLock is idempotent for the same identifier in the same process and returns true immediately).
Could you share a bit more detail so we can reproduce the exact hang?
Your flutter --version and IDE / how hot restart is triggered (flutter runR, VS Code Ctrl+Shift+F5, or full stop & relaunch).
Whether another instance of the app (e.g. an installed Release build in the tray) was running at the same time, or if a debugger breakpoint was hit.
Any console output when it becomes unresponsive.
Also one small note on the snippet above: Application.instance.quit(0) schedules shutdown asynchronously, so if requestSingleInstanceLock returns false, make sure to return; early from main() (or call exit(0)) instead of continuing to initialize the rest of the app and calling runApp().
@lijy91
1.Flutter 3.50.1 Use the IDEA console and press Shift + R to perform a hot restart.
2.Only one instance was run.
3.The console does not output any content, the UI interface freezes, but the program does not immediately exit. After some time, Windows will prompt that the application is unresponsive.
I captured the native stack for this hang. It reproduces with both Shift+R and an uppercase R entered with Caps Lock in the IntelliJ IDEA terminal. Only one instance of ZeroBit Player was running.
Environment
Windows x64, Flutter 3.50.1, Dart 3.14.0
nativeapi_flutter, nativeapi, and cnativeapi 0.6.3
Reproduction
Start ZeroBit Player with flutter run --debug -d windows and let it initialize. The app's Rust code creates a WinRT MediaPlayer for System Media Transport Controls (SMTC).
Put focus in the terminal and press R to hot restart. The new Dart isolate calls WindowManager.instance.getCurrent() during startup.
On a failing restart, the player process stays alive and Windows reports its window as unresponsive. I have also seen successful restarts with the same setup.
The blocked thread is the player's main window thread. I queried the target HWND from the stack. Its window class was MediaPlayer SMTC window - {94D27DC4-C3AE-4AD5-AFEF-666C581E243C}. It belonged to the player process on a different thread. That thread was in WaitOnAddress inside the app's Rust DLL when sampled.
The stack points to the fallback in GetCurrent(). FindCurrentWindowCandidates() synchronously calls GetWindowTextLengthW() for a same-process candidate without a NativeAPI window ID. Windows sends WM_GETTEXTLENGTH to that window, and the caller can wait indefinitely if the owner thread does not pump messages. This accounts for the freeze in this capture. The single-instance lock was my initial hypothesis. Source at the core revision used by 0.6.3 · GetWindowTextLengthW documentation
Could the candidate scan avoid an unbounded cross-thread title query? For example, a bounded WM_GETTEXTLENGTH via SendMessageTimeoutW could skip a timed-out candidate and continue looking for the app's main window. The expected behavior is for the lookup to finish even if another same-process window cannot answer.
Activity
lijy91 commentedon Dec 4, 2026
Thanks for reporting @Empty-57!
We tested hot restart (
Shift+R/Rinflutter run -d windows) on Windows 11 with bothflutter_single_instance_exampleandZeroBit-Player(withif (kDebugMode) return;removed, usingnativeapi_flutter: 0.6.3), and consecutive hot restarts completed in <1s with the window remaining responsive (RequestSingleInstanceLockis idempotent for the same identifier in the same process and returnstrueimmediately).Could you share a bit more detail so we can reproduce the exact hang?
flutter --versionand IDE / how hot restart is triggered (flutter runR, VS CodeCtrl+Shift+F5, or full stop & relaunch).Also one small note on the snippet above:
Application.instance.quit(0)schedules shutdown asynchronously, so ifrequestSingleInstanceLockreturnsfalse, make sure toreturn;early frommain()(or callexit(0)) instead of continuing to initialize the rest of the app and callingrunApp().Empty-57 commentedon Dec 4, 2026
@lijy91
1.Flutter 3.50.1 Use the IDEA console and press Shift + R to perform a hot restart.
2.Only one instance was run.
3.The console does not output any content, the UI interface freezes, but the program does not immediately exit. After some time, Windows will prompt that the application is unresponsive.
Empty-57 commentedon Dec 4, 2026
I captured the native stack for this hang. It reproduces with both
Shift+Rand an uppercaseRentered with Caps Lock in the IntelliJ IDEA terminal. Only one instance of ZeroBit Player was running.Environment
nativeapi_flutter,nativeapi, andcnativeapi0.6.3Reproduction
flutter run --debug -d windowsand let it initialize. The app's Rust code creates a WinRTMediaPlayerfor System Media Transport Controls (SMTC).Rto hot restart. The new Dart isolate callsWindowManager.instance.getCurrent()during startup.WinDbg capture
The blocked thread is the player's main window thread. I queried the target HWND from the stack. Its window class was
MediaPlayer SMTC window - {94D27DC4-C3AE-4AD5-AFEF-666C581E243C}. It belonged to the player process on a different thread. That thread was inWaitOnAddressinside the app's Rust DLL when sampled.The stack points to the fallback in
GetCurrent().FindCurrentWindowCandidates()synchronously callsGetWindowTextLengthW()for a same-process candidate without a NativeAPI window ID. Windows sendsWM_GETTEXTLENGTHto that window, and the caller can wait indefinitely if the owner thread does not pump messages. This accounts for the freeze in this capture. The single-instance lock was my initial hypothesis. Source at the core revision used by 0.6.3 · GetWindowTextLengthW documentationCould the candidate scan avoid an unbounded cross-thread title query? For example, a bounded
WM_GETTEXTLENGTHviaSendMessageTimeoutWcould skip a timed-out candidate and continue looking for the app's main window. The expected behavior is for the lookup to finish even if another same-process window cannot answer.lijy91 commentedon Dec 4, 2026
Thank you for the WinDbg capture @Empty-57 — that pinpointed the exact deadlock immediately!
Fixed in libnativeapi/nativeapi-core#116 and #87:
GetWindowTextLengthWcalls inWindowManager::GetCurrent()(FindCurrentWindowCandidates) andWindowManager::GetAll()(EnumWindowsCallback) with a boundedSendMessageTimeoutW(..., WM_GETTEXTLENGTH, ..., SMTO_ABORTIFHUNG | SMTO_NORMAL, 50, ...)helper, skipping unresponsive worker-thread windows (such as WinRT SMTC helper HWNDs).window_manager_get_current_windows_test).This fix will be included in the next
cnativeapi/nativeapipatch release.