feat(observability): write a server heap snapshot on SIGUSR2 (#13694)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
6530de0339
commit
1dc8cbe6d1
4 files changed
+127
No files matched your search
@@ -618,3 +618,40 @@ Current high-value span and metric boundaries include:
|
||||
- logs outside spans are not persisted in the trace file; SSH-managed launch stdout/stderr is still
|
||||
captured in its launcher log
|
||||
- metrics are not snapshotted locally
|
||||
|
||||
## Heap Snapshots
|
||||
|
||||
To see what a long-running server holds in memory, send it `SIGUSR2`. The server writes a V8 heap
|
||||
snapshot to its logs dir and logs the path. This works for desktop, `npx t3`, and service installs
|
||||
on macOS and Linux. Windows has no `SIGUSR2`.
|
||||
|
||||
Send the signal to the server pid in `server-runtime.json`, which sits in the server's state dir
|
||||
next to the `logs` dir. For a dev server or a `--home-dir` launch, use that server's state dir from
|
||||
[Traces](#traces). Do not send it to the desktop app or the service launcher: a process without the
|
||||
handler exits on `SIGUSR2`. After a crash the file can keep a stale pid that now belongs to a
|
||||
different process, so check the pid first.
|
||||
|
||||
```bash
|
||||
pid="$(jq .pid "${T3CODE_HOME:-$HOME/.t3}/userdata/server-runtime.json")"
|
||||
ps -p "$pid" -o command=
|
||||
```
|
||||
|
||||
If `ps` shows the T3 Code server, send the signal:
|
||||
|
||||
```bash
|
||||
kill -USR2 "$pid"
|
||||
```
|
||||
|
||||
The file is `<logsDir>/server-<pid>-<timestamp>.heapsnapshot`, next to `server.trace.ndjson`. To
|
||||
open it, use the Memory tab in Chrome DevTools and select Load.
|
||||
|
||||
Before you take one:
|
||||
|
||||
- The server stops while it writes the file. For a large heap this can take a minute or more.
|
||||
Connected clients can reconnect during the pause, and an event loop monitor, if the server has
|
||||
one, records the pause as a stall. Send the signal once. A second signal sent during a write
|
||||
takes another snapshot after the first one finishes.
|
||||
- The write needs about as much free memory as the heap uses. On a machine that is already
|
||||
swapping, it can make the problem worse or crash the server.
|
||||
- The file contains everything in server memory, including tokens, secrets, and thread content. Do
|
||||
not share it publicly. Delete it when you are done, because storage cleanup does not remove it.
|
||||
Reference in new issue
Block a user