mattn / anko

Scriptable interpreter written in golang
http://play-anko.appspot.com/
MIT License
1.47k stars 118 forks source link

Cannot use vm in multiple goroutines #329

Closed dgrr closed 4 years ago

dgrr commented 4 years ago

Hello,

I am getting the following panic message:

fatal error: concurrent map read and map write

goroutine 7085 [running]:
runtime.throw(0xde958c, 0x21)
    /usr/lib/go/src/runtime/panic.go:774 +0x72 fp=0xc003366188 sp=0xc003366158 pc=0x42f902
runtime.mapaccess2_faststr(0xcbf780, 0xc00015fa70, 0xc001981430, 0x7, 0x7, 0xc90340)
    /usr/lib/go/src/runtime/map_faststr.go:116 +0x48f fp=0xc0033661f8 sp=0xc003366188 pc=0x4148bf
github.com/mattn/anko/vm.(*runInfoStruct).invokeExpr(0xc000897a00)
    /home/dgrr/.go/src/github.com/mattn/anko/vm/vmExpr.go:515 +0x32f2 fp=0xc0033669a0 sp=0xc0033661f8 pc=0x8b8652
github.com/mattn/anko/vm.(*runInfoStruct).runSingleStmt(0xc000897a00)
    /home/dgrr/.go/src/github.com/mattn/anko/vm/vmStmt.go:146 +0x2ff fp=0xc003366f40 sp=0xc0033669a0 pc=0x8cab3f
github.com/mattn/anko/vm.(*runInfoStruct).runSingleStmt(0xc000897a00)
    /home/dgrr/.go/src/github.com/mattn/anko/vm/vmStmt.go:86 +0x2faf fp=0xc0033674e0 sp=0xc003366f40 pc=0x8cd7ef
github.com/mattn/anko/vm.RunContext(0xffff60, 0xc0000d4010, 0xc0019acb70, 0x0, 0xff5fc0, 0xc0019acc30, 0xd4277fceba22319f, 0xc0019b4f20, 0xd400000000d875c0, 0xc000545401)
    /home/dgrr/.go/src/github.com/mattn/anko/vm/vmStmt.go:44 +0x134 fp=0xc0033675a0 sp=0xc0033674e0 pc=0x8ca6e4
github.com/mattn/anko/vm.Execute(0xc0019acb70, 0x0, 0xc0054a2900, 0x8e, 0xc0006e4568, 0x0, 0x0, 0x4834f1)
    /home/dgrr/.go/src/github.com/mattn/anko/vm/vmStmt.go:20 +0x168 fp=0xc003367628 sp=0xc0033675a0 pc=0x8ca558
main.(*scriptRunner).Run(0xc003cd4c90, 0xc00183114f, 0x5, 0x0, 0x0)
    /home/user/myproject/engine.go:27 +0x532 fp=0xc003367760 sp=0xc003367628 pc=0xc14822
dgrr commented 4 years ago

The error happens when accessing to env.Packages image

dgrr commented 4 years ago

How can I isolate the packages by env?

dgrr commented 4 years ago

Setting the Packages in the init function worked. image