You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
INF-1318 flock config.yaml updates against concurrent writers
Han-9 from the adversarial review: the load-modify-write cycle in
SetContext / UseContext / DeleteContext was not protected against two
twoctl invocations racing on the same config.yaml. The later os.Rename
won; the earlier update was lost. Realistic trigger: background
'twoctl config use-context' while a foreground 'auth login' completes.
Now wrapped with withLock(), an exclusive advisory flock on
config.yaml.lock. Implementation split by build tag:
- lock_unix.go: syscall.Flock(LOCK_EX) - blocking, per-fd, released
on file close. Works on linux, darwin, *bsd.
- lock_windows.go: no-op for now. Windows residual race documented;
proper fix needs LockFileEx via golang.org/x/sys/windows in a
follow-up.
- lock.go: shared dirOf helper.
No new third-party deps. Test confirms unix serialisation: 10 goroutines
contending for the same lockfile never enter the critical section
concurrently.
0 commit comments