Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Event loop stalls of 10–60 s on HDD-backed hosts make T3 Connect reconnects time out (mint-credential / websocket-ticket) despite a healthy tunnel #37373

Closedg-ongenae(GitHub profile, opens in a new tab) opened this issue 1 comment

Before submitting

  • I searched existing issues and did not find a duplicate. #15707 and #19242 cover WAL fsyncs on slow disks; that fix (synchronous = NORMAL, #19205) is in the build used here and the stalls continue. #14701 covers one read path. #31829 and #5744 report reconnect trouble through T3 Connect on healthy tunnels and may share this cause.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Run t3 serve (0.1.9) as a headless Linux background service with T3 Connect (managed tunnel). Put ~/.t3/userdata on a rotational disk; here it is a 7200 rpm HDD on a 2-core, 4 GB machine.
  2. Use it normally for a few days with agent sessions. statev2.sqlite reaches about 390 MB.
  3. Reconnect from another device through T3 Connect, for example by returning to the app or reloading the web client.

Expected behavior

The server answers the reconnect requests (mint-credential, websocket-ticket, the websocket upgrade) within the client's timeout. Slow storage should make things slower, not stop the server from responding entirely.

Actual behavior

The server's event loop freezes for tens of seconds. Requests arriving through the relay during a freeze hit the client timeout, and cloudflared logs Incoming request ended abruptly: context canceled. The client keeps retrying and appears unable to reconnect. The tunnel stays healthy the whole time: 4 QUIC connections, never unregistered.

Numbers from event-loop-stalls.ndjson and relay-client.ndjson since installing 0.1.9 (about 4 days):

  • Freezes. 379 stalls, median 3.8 s, p90 11.6 s, max 63.5 s. 138 lasted over 5 s and 54 over 10 s.
  • Most long freezes are I/O wait, not compute. 80 of the 138 stalls over 5 s used less than 5% CPU during the stall. For example, the 63.5 s stall used 57 ms of CPU (cpuUserMs 45 + cpuSystemMs 12). The main thread is blocked in synchronous SQLite or disk I/O.
  • Dropped requests. 196 requests through the relay ended with "context canceled", and 158 of them fell inside a logged stall. By endpoint:
    • websocket upgrades: 98
    • /api/t3-connect/mint-credential: 49
    • /api/auth/websocket-ticket/rpc: 15
    • /api/orchestration/shell: 10
    • /.well-known/t3/environment: 5
    • /api/t3-connect/health: 5
  • Example. One 56 s stall swallowed 3 consecutive mint-credential attempts plus a websocket-ticket request.
  • Slow startup. About 85 s from process start to "T3 Connect is reachable" (51 s of that before "Listening"). Reconnects fail during that window too.

Database at the time: statev2.sqlite 393 MB, WAL mode, 4 KB pages. 25,490 free pages (about 100 MB, 27% of the file) were scattered through it, which hurts a lot on an HDD. Largest objects:

  • orchestration_v2_projection_turn_items: 100 MB
  • orchestration_events: 59 MB
  • orchestration_v2_projection_nodes: 39 MB

A manual VACUUM brought it to 279 MB with 0 free pages. Nothing in the app ever reclaims that space.

Suggestions:

  1. Keep auth and relay endpoints off the paths that block. mint-credential, websocket-ticket and health shouldn't have to wait behind database work on the main loop, for example by running SQLite in a worker thread.
  2. Reclaim free space automatically: PRAGMA auto_vacuum = INCREMENTAL plus a periodic incremental_vacuum, or a VACUUM at startup when the freelist ratio is high.
  3. Raise the SQLite page cache and/or mmap_size so hot pages don't hit the disk. Only synchronous is set today, as far as I can tell from the bundle.
  4. Prune or compact old orchestration_events and turn items for threads that are settled or archived.

Impact

Major degradation or frequent failure

Version or commit

0.1.9 (Linux AppImage, server run headless via t3code serve)

Environment

Debian 13 (kernel 6.12), x86_64, 2 cores, 3.7 GB RAM, state on a 7200 rpm SATA HDD (ext4, mq-deadline). T3 Connect managed tunnel, cloudflared 2026.10.4 over QUIC. Providers: Claude, Codex.

Logs or stack traces

# event-loop-stalls.ndjson (worst entries)
{"time":"2026-11-13T16:30:31.400Z","delayMaxMs":63492,"utilization":0.95,"cpuUserMs":45,"cpuSystemMs":12,"majorPageFaults":0,"minorPageFaults":938,"involuntaryContextSwitches":8,"rssMb":285}
{"time":"2026-11-14T17:32:51.407Z","delayMaxMs":55975,"utilization":0.95,"cpuUserMs":32,"cpuSystemMs":39,"majorPageFaults":0,"minorPageFaults":2605,"involuntaryContextSwitches":26,"rssMb":290}

# server log around the 56 s stall (tunnel identifiers redacted)
[18:32:51.391] WARN Relay client reported a transport warning
  output: 'ERR Request failed error="Incoming request ended abruptly: context canceled" connIndex=0 dest=https://<relay-host>/api/auth/websocket-ticket/rpc type=http'
[18:32:51.392] WARN Relay client reported a transport warning
  output: 'ERR Request failed error="Incoming request ended abruptly: context canceled" connIndex=2 dest=https://<relay-host>/api/t3-connect/mint-credential type=http'
[18:32:51.392] WARN Relay client reported a transport warning
  output: 'ERR Request failed error="Incoming request ended abruptly: context canceled" connIndex=2 dest=https://<relay-host>/api/t3-connect/mint-credential type=http'
[18:32:51.407] WARN event loop stalled for 55975 ms
[18:32:52.016] WARN Relay client reported a transport warning
  output: 'ERR Request failed error="Incoming request ended abruptly: context canceled" connIndex=3 dest=https://<relay-host>/api/t3-connect/mint-credential type=http'

Workaround

  • Stop the service and run VACUUM on statev2.sqlite. This reclaimed 27% of the file here.
  • Move ~/.t3/userdata to an SSD.
  1. This is the same problem as #30065, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.

  2. juliusmarminge closed this

Sign in to join this conversation.