Commit 11ffe47
committed
ui: fix data race on spinner Suffix between label updates and render goroutine
The spinner library (briandowns/spinner) reads s.Prefix and s.Suffix
inside s.mu on every tick. renderProgress was writing u.spinner.Suffix
directly from the calling goroutine without holding s.mu — a genuine
data race. On amd64 a string is pointer+length (two 64-bit words), so
a concurrent write can produce a torn read where pointer and length are
from different updates, yielding garbage output or the wrong label text
for one frame. go test -race confirms the race is now gone.
Fix: add pendingSuffix to spinnerWriter. renderProgress writes it under
sw.mu. A PreUpdate callback on the spinner (called while s.mu is held,
before s.Suffix is read for the frame) applies pendingSuffix to s.Suffix
atomically. Lock order is s.mu → sw.mu, consistent with how the spinner
goroutine already calls sw.Write under s.mu.
This eliminates the 'Resolving actions' / 'Planning pins' label text
flickering at phase transitions: the label now only changes at tick
boundaries, never mid-frame, and never races with the render goroutine.1 parent efecf4b commit 11ffe47
1 file changed
Lines changed: 38 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
367 | 376 | | |
368 | 377 | | |
369 | 378 | | |
| |||
1054 | 1063 | | |
1055 | 1064 | | |
1056 | 1065 | | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
1057 | 1076 | | |
1058 | 1077 | | |
1059 | 1078 | | |
| |||
1308 | 1327 | | |
1309 | 1328 | | |
1310 | 1329 | | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
1314 | 1341 | | |
1315 | | - | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
1316 | 1350 | | |
1317 | 1351 | | |
1318 | 1352 | | |
| |||
0 commit comments