Using fsnotify in a plugin causes a crash

0

I am building a toy project to learn Go and run into a crash that only occurs when running some code that uses fsnotify inside a plugin. If I just compile everything in a single binary then it works as expected.

It seems like sometimes it crashes as soon as it starts up but sometimes it crashes only when a fsnotify event occurs.

My source code here, specifically commenting/uncommenting line 132/133 in core/engine.go to change between using the plugin and compiling it as a single binary.

go version go1.10 darwin/amd64

go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ltse/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ltse/go"
GORACE=""
GOROOT="/usr/local/go"

GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k4/83ly40d15rzfvydw_p7pt2248j0fgr/T/go-build828136956=/tmp/go
-build -gno-record-gcc-switches -fno-common"

Error log:

config: config.json
2018/02/27 22:45:04 Loaded watchdir plugin
2018/02/27 22:45:04 watchdirTrigger running
2018/02/27 22:45:04 Added .
2018/02/27 22:45:04 Added .git
runtime: bad pointer in frame github.com/go-fsnotify/fsnotify.(*Watcher).readEvents at 0xc42004ed78: 0x9
fatal error: invalid pointer found on stack

runtime stack:
runtime.throw(0x50ff5a5, 0x1e)
    /usr/local/go/src/runtime/panic.go:619 +0x81 fp=0x70000bb8f6f8 sp=0x70000bb8f6d8 pc=0x5028971
runtime.adjustpointers(0xc42004ed18, 0x70000bb8f7f0, 0x70000bb8fbc0, 0x5178668, 0x5181820)
    /usr/local/go/src/runtime/stack.go:592 +0x23e fp=0x70000bb8f768 sp=0x70000bb8f6f8 pc=0x503e08e
runtime.adjustframe(0x70000bb8fad0, 0x70000bb8fbc0, 0x5181820)
    /usr/local/go/src/runtime/stack.go:663 +0x32c fp=0x70000bb8f820 sp=0x70000bb8f768 pc=0x503e3dc
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc420001980, 0x0, 0x0, 0x7fffffff, 0x51028e0, 0x70000bb8fbc0, 0x0, ...)
    /usr/local/go/src/runtime/traceback.go:355 +0x136c fp=0x70000bb8fb38 sp=0x70000bb8f820 pc=0x504713c
runtime.copystack(0xc420001980, 0x1000, 0x1)
    /usr/local/go/src/runtime/stack.go:891 +0x26e fp=0x70000bb8fcf0 sp=0x70000bb8fb38 pc=0x503eece
runtime.newstack()
    /usr/local/go/src/runtime/stack.go:1063 +0x310 fp=0x70000bb8fe80 sp=0x70000bb8fcf0 pc=0x503f2e0
runtime: unexpected return pc for runtime.morestack called from 0x0
stack: frame={sp:0x70000bb8fe80, fp:0x70000bb8fe88} stack=[0x70000bb10290,0x70000bb8fe90)
000070000bb8fd80:  000000c420000d80  000000c420072148 
000070000bb8fd90:  0000000800000001  000000c420024a00 
000070000bb8fda0:  000000c4200720d8  000000c420072000 
000070000bb8fdb0:  000070000bb8fdd0  0000000004031db8 <runtime.wakep+72> 
000070000bb8fdc0:  000000c420001980  000000c420042480 
000070000bb8fdd0:  00000000050b788a <github.com/go-fsnotify/fsnotify.(*Watcher).readEvents+826>  000000c420001980 
000070000bb8fde0:  0000000000000000  0000000000000000 
000070000bb8fdf0:  0000000000000000  0000000000000000 
000070000bb8fe00:  000000c420001980  0000000000000000 
000070000bb8fe10:  000000c420000a00  0000000000000000 
000070000bb8fe20:  000000c420001980  000000c420000d80 
000070000bb8fe30:  00000000041dfe40  000070000bb8fe68 
000070000bb8fe40:  0000000004033766 <runtime.park_m+182>  000000c420000a80 
000070000bb8fe50:  00000000041dfe40  000000c420022501 
000070000bb8fe60:  000000c420000d80  000000c420040758 
000070000bb8fe70:  000000c4200427c8  000000000504d1a9 <runtime.morestack+137> 
000070000bb8fe80: <0000000000000000 >0100000004300000 
runtime.morestack()
    /usr/local/go/src/runtime/asm_amd64.s:480 +0x89 fp=0x70000bb8fe88 sp=0x70000bb8fe80 pc=0x504d1a9

goroutine 6 [copystack]:
runtime.selectgo(0xc42004ed88, 0xc42008a240)
    /usr/local/go/src/runtime/select.go:202 +0x174b fp=0xc42004ec80 sp=0xc42004ec78 pc=0x5038c5b
github.com/go-fsnotify/fsnotify.(*Watcher).readEvents(0xc420074120)
    /Users/ltse/go/src/github.com/go-fsnotify/fsnotify/kqueue.go:317 +0x33a fp=0xc42004efd8 sp=0xc42004ec80 pc=0x50b788a
runtime: unexpected return pc for runtime.goexit called from 0xc420074120
stack: frame={sp:0xc42004efd8, fp:0xc42004efe0} stack=[0xc42004e000,0xc42004f000)
000000c42004eed8:  0000000000000000  0000000000000000 
000000c42004eee8:  0000000000000000  0000000000000000 
000000c42004eef8:  0000000000000000  0000000000000000 
000000c42004ef08:  0000000000000000  0000000000000000 
000000c42004ef18:  0000000000000000  0000000000000000 
000000c42004ef28:  0000000000000000  0000000000000000 
000000c42004ef38:  0000000000000000  0000000000000000 
000000c42004ef48:  0000000000000000  0000000000000000 
000000c42004ef58:  0000000000000000  0000000000000000 
000000c42004ef68:  0000000000000000  0000000000000000 
000000c42004ef78:  0000000000000000  0000000000000000 
000000c42004ef88:  0000000000000000  0000000000000000 
000000c42004ef98:  0000000000000000  0000000000000000 
000000c42004efa8:  0000000000000000  0000000000000000 
000000c42004efb8:  0000000000000000  0000000000000000 
000000c42004efc8:  0000000000000000  000000000504f621 <runtime.goexit+1> 
000000c42004efd8: <000000c420074120 >0000000000000000 
000000c42004efe8:  0000000000000000  0000000000000000 
000000c42004eff8:  0000000000000000 
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc42004efe0 sp=0xc42004efd8 pc=0x504f621
created by github.com/go-fsnotify/fsnotify.NewWatcher
    /Users/ltse/go/src/github.com/go-fsnotify/fsnotify/kqueue.go:62 +0x1a6

goroutine 1 [chan receive]:
runtime.gopark(0x41370c0, 0xc42008a178, 0x412f496, 0xc, 0x4011917, 0x3)
    /usr/local/go/src/runtime/proc.go:291 +0x11a fp=0xc420065cb8 sp=0xc420065c98 pc=0x402d80a
runtime.goparkunlock(0xc42008a178, 0x412f496, 0xc, 0x17, 0x3)
    /usr/local/go/src/runtime/proc.go:297 +0x5e fp=0xc420065cf8 sp=0xc420065cb8 pc=0x402d8be
runtime.chanrecv(0xc42008a120, 0x0, 0x40ff201, 0xc420065dc8)
    /usr/local/go/src/runtime/chan.go:518 +0x2f2 fp=0xc420065d90 sp=0xc420065cf8 pc=0x40067a2
runtime.chanrecv1(0xc42008a120, 0x0)
    /usr/local/go/src/runtime/chan.go:400 +0x2b fp=0xc420065dc0 sp=0xc420065d90 pc=0x400649b
github.com/dk1027/scv/core.NewEngine(0xc4200ae000, 0x1, 0x4, 0x0, 0x0, 0x0)
    /Users/ltse/go/src/github.com/dk1027/scv/core/engine.go:125 +0x339 fp=0xc420065ed8 sp=0xc420065dc0 pc=0x40e41c9
main.main()
    /Users/ltse/go/src/github.com/dk1027/scv/main.go:28 +0x165 fp=0xc420065f88 sp=0xc420065ed8 pc=0x40e4b35
runtime.main()
    /usr/local/go/src/runtime/proc.go:198 +0x212 fp=0xc420065fe0 sp=0xc420065f88 pc=0x402d3b2
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420065fe8 sp=0xc420065fe0 pc=0x40565c1

goroutine 2 [force gc (idle)]:
runtime.gopark(0x41370c0, 0x41dfe40, 0x412fb96, 0xf, 0x4136f14, 0x1)
    /usr/local/go/src/runtime/proc.go:291 +0x11a fp=0xc420040768 sp=0xc420040748 pc=0x402d80a
runtime.goparkunlock(0x41dfe40, 0x412fb96, 0xf, 0x14, 0x1)
    /usr/local/go/src/runtime/proc.go:297 +0x5e fp=0xc4200407a8 sp=0xc420040768 pc=0x402d8be
runtime.forcegchelper()
    /usr/local/go/src/runtime/proc.go:248 +0xcc fp=0xc4200407e0 sp=0xc4200407a8 pc=0x402d64c
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4200407e8 sp=0xc4200407e0 pc=0x40565c1
created by runtime.init.4
    /usr/local/go/src/runtime/proc.go:237 +0x35

goroutine 3 [GC sweep wait]:
runtime.gopark(0x41370c0, 0x41dff20, 0x412f68d, 0xd, 0x401f814, 0x1)
    /usr/local/go/src/runtime/proc.go:291 +0x11a fp=0xc420040f60 sp=0xc420040f40 pc=0x402d80a
runtime.goparkunlock(0x41dff20, 0x412f68d, 0xd, 0x14, 0x1)
    /usr/local/go/src/runtime/proc.go:297 +0x5e fp=0xc420040fa0 sp=0xc420040f60 pc=0x402d8be
runtime.bgsweep(0xc420070000)
    /usr/local/go/src/runtime/mgcsweep.go:52 +0xa3 fp=0xc420040fd8 sp=0xc420040fa0 pc=0x401f923
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420040fe0 sp=0xc420040fd8 pc=0x40565c1
created by runtime.gcenable
    /usr/local/go/src/runtime/mgc.go:216 +0x58

goroutine 4 [finalizer wait]:
runtime.gopark(0x41370c0, 0x41fc300, 0x412f966, 0xe, 0x14, 0x1)
    /usr/local/go/src/runtime/proc.go:291 +0x11a fp=0xc420041718 sp=0xc4200416f8 pc=0x402d80a
runtime.goparkunlock(0x41fc300, 0x412f966, 0xe, 0x14, 0x1)
    /usr/local/go/src/runtime/proc.go:297 +0x5e fp=0xc420041758 sp=0xc420041718 pc=0x402d8be
runtime.runfinq()
    /usr/local/go/src/runtime/mfinal.go:175 +0xad fp=0xc4200417e0 sp=0xc420041758 pc=0x40169cd
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4200417e8 sp=0xc4200417e0 pc=0x40565c1
created by runtime.createfing
    /usr/local/go/src/runtime/mfinal.go:156 +0x62

goroutine 5 [runnable]:
syscall.Syscall(0x5, 0xc4200f6000, 0x8000, 0x1c0, 0x15, 0x0, 0x0)
    /usr/local/go/src/syscall/asm_darwin_amd64.s:16 +0x5 fp=0xc4200538c0 sp=0xc4200538b8 pc=0x505d495
golang.org/x/sys/unix.Open(0xc4200f2000, 0xb, 0x8000, 0xc4000001c0, 0x0, 0x0, 0x0)
    /Users/ltse/go/src/golang.org/x/sys/unix/zsyscall_darwin_amd64.go:1025 +0x90 fp=0xc420053930 sp=0xc4200538c0 pc=0x50b5860
github.com/go-fsnotify/fsnotify.(*Watcher).addWatch(0xc420074120, 0xc4200f2000, 0xb, 0xc40000002b, 0x50b379f, 0xc420053aa8, 0x2, 0x2)
    /Users/ltse/go/src/github.com/go-fsnotify/fsnotify/kqueue.go:218 +0x617 fp=0xc4200539c0 sp=0xc420053930 pc=0x50b7297
github.com/go-fsnotify/fsnotify.(*Watcher).internalWatch(0xc420074120, 0xc4200f2000, 0xb, 0x4148760, 0xc4200e0410, 0xc4200ea000, 0x9, 0x0, 0x0)
    /Users/ltse/go/src/github.com/go-fsnotify/fsnotify/kqueue.go:478 +0x13e fp=0xc420053a20 sp=0xc4200539c0 pc=0x50b865e
github.com/go-fsnotify/fsnotify.(*Watcher).watchDirectoryFiles(0xc420074120, 0xc420016748, 0x4, 0x4, 0xc4200dc08c)
    /Users/ltse/go/src/github.com/go-fsnotify/fsnotify/kqueue.go:399 +0x1db fp=0xc420053ad8 sp=0xc420053a20 pc=0x50b7f3b
github.com/go-fsnotify/fsnotify.(*Watcher).addWatch(0xc420074120, 0xc420016748, 0x4, 0x2b, 0xc4200da089, 0xa, 0x0, 0x0)
    /Users/ltse/go/src/github.com/go-fsnotify/fsnotify/kqueue.go:251 +0x349 fp=0xc420053b68 sp=0xc420053ad8 pc=0x50b6fc9
github.com/go-fsnotify/fsnotify.(*Watcher).Add(0xc420074120, 0xc420016748, 0x4, 0x1, 0x1)
    /Users/ltse/go/src/github.com/go-fsnotify/fsnotify/kqueue.go:98 +0xac fp=0xc420053bc0 sp=0xc420053b68 pc=0x50b65fc
github.com/dk1027/scv/watchdir.watchDir(0xc420074120, 0xc420016748, 0x4, 0x4148760, 0xc4200e0340, 0x0, 0x0, 0x0, 0x0)
    /Users/ltse/go/src/github.com/dk1027/scv/watchdir/watchdir.go:63 +0xe5 fp=0xc420053c18 sp=0xc420053bc0 pc=0x50bb2e5
github.com/dk1027/scv/watchdir.bindWatchDir.func1(0xc420016748, 0x4, 0x4148760, 0xc4200e0340, 0x0, 0x0, 0x0, 0xc420053cf8)
    /Users/ltse/go/src/github.com/dk1027/scv/watchdir/watchdir.go:53 +0x69 fp=0xc420053c70 sp=0xc420053c18 pc=0x50bb4a9
path/filepath.walk(0xc420016748, 0x4, 0x4148760, 0xc4200e0340, 0xc420056320, 0x0, 0x0)
    /usr/local/go/src/path/filepath/path.go:361 +0xe5 fp=0xc420053d48 sp=0xc420053c70 pc=0x50b3925
path/filepath.walk(0xc420016170, 0x1, 0x4148760, 0xc420096a90, 0xc420056320, 0x0, 0xc420041e70)
    /usr/local/go/src/path/filepath/path.go:381 +0x2cc fp=0xc420053e20 sp=0xc420053d48 pc=0x50b3b0c
path/filepath.Walk(0xc420016170, 0x1, 0xc420056320, 0x0, 0x0)
    /usr/local/go/src/path/filepath/path.go:403 +0x10d fp=0xc420053e80 sp=0xc420053e20 pc=0x50b3d9d
github.com/dk1027/scv/watchdir.(*watchdirTrigger).Run(0xc4200944e0)
    /Users/ltse/go/src/github.com/dk1027/scv/watchdir/watchdir.go:31 +0x13a fp=0xc420053fd8 sp=0xc420053e80 pc=0x50bae9a
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420053fe0 sp=0xc420053fd8 pc=0x40565c1
created by github.com/dk1027/scv/core.(*Rule).Start
    /Users/ltse/go/src/github.com/dk1027/scv/core/engine.go:25 +0x45
go
plugins
crash
asked on Stack Overflow Feb 28, 2018 by King Long Tse

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0