G0.3: watchdog giu 15s khi attach-in-flight (SHM flag) + RAII guard trong attach job (fix kill nham khi GUI mo)

This commit is contained in:
2026-08-15 19:00:32 +07:00
parent 2f7861820e
commit 5313d85926
6 changed files with 41 additions and 3 deletions
+10 -1
View File
@@ -940,6 +940,14 @@ int main(int argc, char* argv[]) {
// a window on a worker whose pump is idle during jobs hangs
// view->attached() (gui_probe: two_workers_close TIMEOUT). The attach
// job runs on the channel worker (COM STA apartment stays alive).
// G0.3: while an attach job is in flight, tell the Tauri watchdog via
// SHM so a long Nexus reload/attach (can exceed 3s) is not mistaken
// for a dead bridge and killed. RAII -> cleared on every exit path.
struct AttachInFlightGuard {
SharedAudioBufferIPC* ipc;
explicit AttachInFlightGuard(SharedAudioBufferIPC* p) : ipc(p) { if (ipc) ipc->attachInFlight = 1; }
~AttachInFlightGuard() { if (ipc) ipc->attachInFlight = 0; }
};
auto handleOpenGui = [&](uint32_t guiCh, uintptr_t arg1, const std::string& pluginId) {
if (!instruments.get(guiCh)) {
std::cerr << "[NativeBridge] GUI deferred ch=" << guiCh
@@ -1029,7 +1037,8 @@ int main(int argc, char* argv[]) {
instruments.setReloading(guiCh, true);
}
}
workers[guiCh]->post([&instruments, guiCh, hwnd, arg2 = pluginId]() {
workers[guiCh]->post([&instruments, shmIPC, guiCh, hwnd, arg2 = pluginId]() {
AttachInFlightGuard _aifGuard{shmIPC};
if (!instruments.get(guiCh)) {
std::cerr << "[NativeBridge] GUI attach FAILED hwnd=" << hwnd
<< " plugin=" << arg2 << " ch=" << guiCh << " (no instrument loaded)" << std::endl;