os: Race condition in (* os.File).readdir() #71496
Labels
BugReport
Issues describing a possible bug in the Go implementation.
FixPending
Issues that have a fix which has not yet been reviewed or submitted.
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Go version
go version go1.23.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
In
os/dir_unix.go
and inos/dir_plan9.go
,(* os.File).readdir()
hasThis code can execute concurrently in two goroutines such that the condition
d == nil
is true in both of them. In this case, each goroutine creates and works with a separate instance ofd = new(dirInfo)
, locks a separate mutexd.mu.Lock()
and possibly races with the otherone over calls tof.pfd.ReadDirent(*d.buf)
.What did you see happen?
/
What did you expect to see?
f.dirinfo.Store(d)
should probably useCompareAndSwap
instead.The text was updated successfully, but these errors were encountered: