Window X calls app.quit(); backendShutdown.finally() calls it again. teardownSshConnection deletes the map entry before SSH exec kill, so the second before-quit saw an empty map and exited while disconnect was still running. Latch the in-flight teardown so the re-entrant quit still waits.