@@ -16,8 +16,10 @@ const CLI_ENTRY = new URL(import.meta.url).pathname;
1616const BUN_EXECUTABLE : string = process . argv [ 0 ] ?? process . execPath ;
1717const READY_WAIT_MS = 2 * 60 * 1000 ;
1818const READY_POLL_MS = 500 ;
19+ const DAEMON_SPAWN_THROTTLE_MS = 3000 ;
1920const LOG_TAIL_BYTES = 200_000 ;
2021const LOG_TAIL_LINES = 40 ;
22+ let lastDaemonSpawnAttemptAt = 0 ;
2123
2224const foregroundRequested = rawArgs . includes ( "--foreground" ) ;
2325const args = foregroundRequested
@@ -93,6 +95,9 @@ function runtimeRunning(state: DaemonState = daemonState()): boolean {
9395function ensureDaemonRunning ( ) : void {
9496 const state = daemonState ( ) ;
9597 if ( managerRunning ( state ) ) return ;
98+ const now = Date . now ( ) ;
99+ if ( now - lastDaemonSpawnAttemptAt < DAEMON_SPAWN_THROTTLE_MS ) return ;
100+ lastDaemonSpawnAttemptAt = now ;
96101 const child = spawn ( BUN_EXECUTABLE , [ CLI_ENTRY , "daemon" ] , {
97102 detached : true ,
98103 stdio : "ignore" ,
@@ -210,7 +215,7 @@ if (args.includes("--help") || args.includes("-h")) {
210215
211216if ( command === "__runtime" ) {
212217 await import ( "./index" ) ;
213- process . exit ( 0 ) ;
218+ await new Promise ( ( ) => { } ) ;
214219}
215220
216221if ( command === "daemon" ) {
@@ -250,7 +255,7 @@ if (command === "start") {
250255
251256if ( foregroundRequested ) {
252257 await import ( "./index" ) ;
253- process . exit ( 0 ) ;
258+ await new Promise ( ( ) => { } ) ;
254259}
255260
256261await startBackground ( ) ;
0 commit comments