Problem
Currently, Windows builds have no file locking:
// lock_windows.go
func (l *FileLock) Lock() error {
once.Do(func() {
fmt.Fprintln(os.Stderr, "warning: file locking not available on Windows...")
})
return nil
}
This means concurrent port-selector invocations on Windows can corrupt the allocations file.
Impact
- Data corruption risk with parallel agents on Windows
- Warning message on every run (via sync.Once per process)
- Windows is a second-class platform
Proposed Solution
Implement Windows file locking using LockFileEx:
// lock_windows.go
import "golang.org/x/sys/windows"
func (l *FileLock) Lock() error {
var overlapped windows.Overlapped
err := windows.LockFileEx(
windows.Handle(l.file.Fd()),
windows.LOCKFILE_EXCLUSIVE_LOCK,
0,
1, 0,
&overlapped,
)
return err
}
func (l *FileLock) Unlock() error {
var overlapped windows.Overlapped
return windows.UnlockFileEx(
windows.Handle(l.file.Fd()),
0,
1, 0,
&overlapped,
)
}
Trade-offs
Pros:
- Full Windows support
- No more warning messages
- Safe concurrent access
Cons:
- New dependency:
golang.org/x/sys/windows
- Need Windows environment for testing
- Increases complexity
Alternative
If Windows is not a priority platform, document this limitation clearly in README and keep current behavior.
Acceptance Criteria
Problem
Currently, Windows builds have no file locking:
This means concurrent
port-selectorinvocations on Windows can corrupt the allocations file.Impact
Proposed Solution
Implement Windows file locking using
LockFileEx:Trade-offs
Pros:
Cons:
golang.org/x/sys/windowsAlternative
If Windows is not a priority platform, document this limitation clearly in README and keep current behavior.
Acceptance Criteria
golang.org/x/sys/windowsdependency