Replace ProcessSemaphore (counting semaphore with N slots) with advisory flock on .beads/dolt-access.lock. Readers acquire shared locks (concurrent), writers acquire exclusive locks (serialized). This prevents multiple bd processes from competing for dolt internal LOCK file, which caused zombie hangs. Key changes: - Add FlockSharedNonBlock/FlockExclusiveNonBlock to lockfile package (unix/windows/wasm) - Add AccessLock with poll-based acquisition and configurable timeout - Integrate lock acquire/release in DoltStore.New()/Close() and error paths - Replace ProcessSemaphore in main.go with OpenTimeout (5s read, 15s write) - Remove dead ProcessSemaphore code Co-Authored-By: beads/crew/lydia <steve.yegge@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Executed-By: beads/crew/emma Rig: beads Role: crew
30 lines
771 B
Go
30 lines
771 B
Go
//go:build unix
|
|
|
|
package lockfile
|
|
|
|
import (
|
|
"os"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// FlockSharedNonBlock acquires a shared non-blocking lock on the file.
|
|
// Multiple processes can hold shared locks concurrently.
|
|
// Returns ErrLockBusy if an exclusive lock is already held.
|
|
func FlockSharedNonBlock(f *os.File) error {
|
|
err := unix.Flock(int(f.Fd()), unix.LOCK_SH|unix.LOCK_NB)
|
|
if err == unix.EWOULDBLOCK {
|
|
return ErrLockBusy
|
|
}
|
|
return err
|
|
}
|
|
|
|
// FlockExclusiveNonBlock acquires an exclusive non-blocking lock on the file.
|
|
// Returns ErrLockBusy if any lock (shared or exclusive) is already held.
|
|
func FlockExclusiveNonBlock(f *os.File) error {
|
|
err := unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB)
|
|
if err == unix.EWOULDBLOCK {
|
|
return ErrLockBusy
|
|
}
|
|
return err
|
|
}
|