Skip to content

Commit 72b2330

Browse files
branchseerclaude
andcommitted
fix: add shutdownTracing() to flush chrome trace before process exit
Rust statics stored in OnceLock are never dropped on process exit, so the ChromeLayer FlushGuard never flushes trace data to disk. Add an explicit shutdown_tracing() NAPI function that drops the guard, and call it from bin.ts before process.exit(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 33340c5 commit 72b2330

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

packages/cli/binding/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ pub fn init() {
4040
TRACING_GUARD.get_or_init(|| std::sync::Mutex::new(crate::cli::init_tracing()));
4141
}
4242

43+
/// Flush and drop the tracing guard. Must be called before process.exit()
44+
/// because Rust statics in OnceLock are never dropped, and the ChromeLayer
45+
/// FlushGuard only writes trace data to disk when dropped.
46+
#[napi]
47+
pub fn shutdown_tracing() {
48+
if let Some(mutex) = TRACING_GUARD.get() {
49+
if let Ok(mut guard) = mutex.lock() {
50+
drop(guard.take());
51+
}
52+
}
53+
}
54+
4355
/// Configuration options passed from JavaScript to Rust.
4456
#[napi(object, object_to_js = false)]
4557
pub struct CliOptions {

packages/cli/src/bin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
const jsStartTime = performance.now();
1414

15-
import { run } from '../binding/index.js';
15+
import { run, shutdownTracing } from '../binding/index.js';
1616
import { doc } from './resolve-doc.js';
1717
import { fmt } from './resolve-fmt.js';
1818
import { lint } from './resolve-lint.js';
@@ -63,10 +63,12 @@ if (command === 'create') {
6363
args: process.argv.slice(2),
6464
})
6565
.then((exitCode) => {
66+
shutdownTracing();
6667
process.exit(exitCode);
6768
})
6869
.catch((err) => {
6970
console.error('[Vite+] run error:', err);
71+
shutdownTracing();
7072
process.exit(1);
7173
});
7274
}

0 commit comments

Comments
 (0)