Skip to content

Commit 725558b

Browse files
author
Marvin Zhang
committed
fix: prevent concurrent dev server starts by adding a lock mechanism
1 parent 7fecffa commit 725558b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/desktop/src-tauri/src/ui_server.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ const DEV_SERVER_DEFAULT_PORT: u16 = 4319;
1313
pub struct UiServerManager {
1414
child: Mutex<Option<Child>>,
1515
url: Mutex<Option<String>>,
16+
start_lock: Mutex<()>,
1617
}
1718

1819
impl UiServerManager {
1920
pub fn new() -> Self {
2021
Self {
2122
child: Mutex::new(None),
2223
url: Mutex::new(None),
24+
start_lock: Mutex::new(()),
2325
}
2426
}
2527

@@ -36,6 +38,11 @@ impl UiServerManager {
3638
return Ok(url);
3739
}
3840

41+
// Prevent concurrent callers from starting multiple dev servers.
42+
// Without this guard, two `ensure_running` calls can race before `self.url` is set,
43+
// which causes multiple `next dev` instances and a `.next/dev/lock` failure.
44+
let _start_guard = self.start_lock.lock();
45+
3946
if let Some(existing) = self.url.lock().clone() {
4047
return Ok(existing);
4148
}
@@ -78,7 +85,6 @@ fn spawn_dev_server(port: u16, project: Option<&DesktopProject>) -> Result<Child
7885
.arg("--filter")
7986
.arg("@leanspec/ui")
8087
.arg("dev")
81-
.arg("--")
8288
.arg("--hostname")
8389
.arg("127.0.0.1")
8490
.arg("--port")

packages/desktop/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"pubkey": ""
7171
},
7272
"shell": {
73-
"sidecar": true
73+
"open": true
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)