rjeczalik / notify

File system event notification library on steroids.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fatal error: checkptr: converted pointer straddles multiple allocations

mna opened this issue · comments

Hello,

I'm getting the error mentioned in the title when running with the -race detector, output is:

fatal error: checkptr: converted pointer straddles multiple allocations

goroutine 160 [running]:
runtime.throw({0x11268e4?, 0xc21f9c?})
	C:/hostedtoolcache/windows/go/1.20.2/x64/src/runtime/panic.go:1047 +0x65 fp=0xc000343e60 sp=0xc000343e30 pc=0x4805c5
runtime.checkptrAlignment(0xc0000903e0?, 0xc000046ea0?, 0x47f013?)
	C:/hostedtoolcache/windows/go/1.20.2/x64/src/runtime/checkptr.go:26 +0x6c fp=0xc000343e80 sp=0xc000343e60 pc=0x44d08c
github.com/rjeczalik/notify.(*readdcw).loopevent(0x0?, 0x1e, 0xc00037e900)
	C:/Users/runneradmin/go/pkg/mod/github.com/rjeczalik/notify@v0.9.3/watcher_readdcw.go:406 +0x12d fp=0xc000343f48 sp=0xc000343e80 pc=0xc2284d
github.com/rjeczalik/notify.(*readdcw).loop(0xc0000737c0)
	C:/Users/runneradmin/go/pkg/mod/github.com/rjeczalik/notify@v0.9.3/watcher_readdcw.go:367 +0xdc fp=0xc000343fc0 sp=0xc000343f48 pc=0xc21f9c
github.com/rjeczalik/notify.(*readdcw).lazyinit.func1()
	C:/Users/runneradmin/go/pkg/mod/github.com/rjeczalik/notify@v0.9.3/watcher_readdcw.go:337 +0x3a fp=0xc000343fe0 sp=0xc000343fc0 pc=0xc21e7a
runtime.goexit()
	C:/hostedtoolcache/windows/go/1.20.2/x64/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000343fe8 sp=0xc000343fe0 pc=0x4b68e1
created by github.com/rjeczalik/notify.(*readdcw).lazyinit
	C:/Users/runneradmin/go/pkg/mod/github.com/rjeczalik/notify@v0.9.3/watcher_readdcw.go:337 +0x117

I wasn't familiar with that error (was expecting a data race warning if a race was found, had never seen that but I usually don't use Windows), but I found the following link that explains it a little: golang/go#54690 (comment)

It appears that this is the line causing the issue: https://github.com/rjeczalik/notify/blob/master/watcher_readdcw.go#L406

Sorry not to provide a small reproducible example, I don't have a Windows machine handy to try to isolate the issue, this is coming from a Github Actions CI run on an internal repo. Thought it'd still be a useful info to report, and let me know if you want me to try a potential fix, this I can do relatively easily.

Thanks,
Martin

EDIT: forgot to mention, this is with

	github.com/rjeczalik/notify v0.9.3

I think

name := syscall.UTF16ToString((*[syscall.MAX_LONG_PATH]uint16)(unsafe.Pointer(&raw.FileName))[:raw.FileNameLength>>1])

Should be

name := syscall.UTF16ToString((*[syscall.MAX_LONG_PATH]uint16)(unsafe.Pointer(&raw.FileName))[:raw.FileNameLength>>1-1])

But don't have access to win at the moment.

Are you able to create a test case the reproduces this issue that we can run in CI?

I also don't have access to Windows but I added a github action on my fork that runs the existing test suite on Windows with the race detector and it does trigger that error: https://github.com/mna/notify/actions/runs/4577859751/jobs/8083780353

I tried your proposed fix but it failes the tests (looking at the results, it appears that the original slicing is correct, the -1 does remove the final letter):

got notify.FileActionAdded: "D:\a\notify\notify\testdata\2701580191\src\github.com\rjeczalik\fs\fs_windows.g"

CI run: https://github.com/mna/notify/actions/runs/4577895135/jobs/8083852947

I also tried with parens as I wasn't sure about the operator precedence of the shift, but yeah same thing.