Commit 604f07a
committed
fix(history): WAL + async UA recording — unblock the listener handler under load
Symptom: HTTPS unresponsive after several listener connects in
quick succession. Login UI hung; /healthz times out; ss shows
CLOSE_WAIT pile-up. Journal had:
/private/tmp/tinyice-push/relay/history.go:126 SLOW SQL >= 200ms
[1784.950ms] [rows:1] INSERT INTO 'user_agents' …
Root cause: every Listener / Source connect calls History.RecordUA
synchronously. Default SQLite mode is rollback-journal with
synchronous=FULL, so each commit fsyncs the entire DB file. Under
burst load (robodj-watchdog reconnecting on three mounts at once)
the writes serialised on the SQLite write lock at >1 s each. Login
also touches the DB to validate the user, so it queued behind the
RecordUA backlog and the operator saw 'login does nothing'.
Two changes:
1. Open the DB with PRAGMA journal_mode=WAL,
synchronous=NORMAL, busy_timeout=5000. Writers no longer
fsync the whole DB; readers don't block writers; brief
contention waits up to 5 s for the lock instead of bubbling
SQLITE_BUSY up to the handler. Per-write latency drops from
~1 s to <5 ms in normal conditions.
2. RecordUA now runs the actual INSERT in a fire-and-forget
goroutine. The listener / source connect handlers return
immediately; the UA counter still accumulates in the
background. We accept losing a UA write on a hard crash —
it's a frequency counter, not transactional state.1 parent 9f89081 commit 604f07a
1 file changed
Lines changed: 28 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
56 | 68 | | |
57 | | - | |
| 69 | + | |
| 70 | + | |
58 | 71 | | |
59 | 72 | | |
60 | 73 | | |
| |||
115 | 128 | | |
116 | 129 | | |
117 | 130 | | |
118 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
119 | 136 | | |
120 | 137 | | |
121 | 138 | | |
122 | 139 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
131 | 149 | | |
132 | 150 | | |
133 | 151 | | |
| |||
0 commit comments