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
What went wrong:
I tried to use read from Watcher.Events while multiple directories were being watched. Testing with the race detector, I found a race condition. FsEvents returned from Wather.ReadSingleEvent are directly casted using an unsafe.Pointer. Watcher.eventBuffer is reused between Wather.ReadSingleEvent calls, so when unix.Read writes to w.eventBuffer, it may write to the same memory of a previously returned FsEvents.
Steps to reproduce, or a short snippet of code that reproduces the problem:
Please run and paste the output of the following commands:
go version:
go version go1.21.0 linux/amd64
go env | grep "CGO_ENABLED\|GOOS":
GOOS='linux'
CGO_ENABLED='1'
uname -r:
6.4.6-76060406-generic
Additional context:
I think Wather.ReadSingleEvent should be removed and Watcher.Watch should be refactored so all events from a single unix.Read use a unique buffer. I'll see how easy this is and open a PR if it's doable.
The text was updated successfully, but these errors were encountered:
What went wrong:
I tried to use read from
Watcher.Events
while multiple directories were being watched. Testing with the race detector, I found a race condition.FsEvents
returned fromWather.ReadSingleEvent
are directly casted using anunsafe.Pointer
.Watcher.eventBuffer
is reused betweenWather.ReadSingleEvent
calls, so whenunix.Read
writes tow.eventBuffer
, it may write to the same memory of a previously returnedFsEvents
.Steps to reproduce, or a short snippet of code that reproduces the problem:
Build https://github.com/tywkeene/go-fsevents/blob/master/examples/loop/loop.go with the race detector and trigger many file events quickly.
System and build environment information
Please run and paste the output of the following commands:
go version
:go version go1.21.0 linux/amd64
go env | grep "CGO_ENABLED\|GOOS"
:GOOS='linux'
CGO_ENABLED='1'
uname -r
:6.4.6-76060406-generic
Additional context:
I think
Wather.ReadSingleEvent
should be removed andWatcher.Watch
should be refactored so all events from a singleunix.Read
use a unique buffer. I'll see how easy this is and open a PR if it's doable.The text was updated successfully, but these errors were encountered: