wasilibs / go-re2

Drop-in replacement for regexp using re2, for any Go app
MIT License
140 stars 16 forks source link

wasm error: unaligned atomic #90

Open goingaround opened 7 months ago

goingaround commented 7 months ago

Hi, im using the regexp with 20 goroutines and getting this panic, with v1.5.2

panic: wasm error: unaligned atomic
        wasm stack trace:
            .$189(i32)
            .$403(i32)
            .$534(i32,i32)
            .$795(i32,i32,i32,i32,i32,i32,i32) i32
            .$813(i32,i32,i32,i32,i32,i32,i32,i32) i32 [runtime.gopanic() panic.go:770]
anuraaga commented 7 months ago

Hi @goingaround - thanks for the report. Would you be able to provide a repro, even a flaky one? We currently have this test that uses 20 goroutines and haven't seen it fail so there might be something we are missing

https://github.com/wasilibs/go-re2/blob/main/concurrency_test.go

goingaround commented 7 months ago

@anuraaga i got ~150 patterns, and the functionality is that every value needs to go through all scanners instead of canning sequentially im having some kind of concurrency setup i got x workers and have request/response structs. every request names the pattern type and every worker returns his result to a response channel. with sequential scan i got scanning 200mb file on 110s with 10 workers i got it down to 15s when i checked 20, i got the crash

i cant share the code itself, and the patterns especially but i can try to write something similar if needed

goingaround commented 7 months ago

actually noticed now that with smaller file (5mb) it seems to work ok, so i guess its related also to how many regexps are running in the same moment

anuraaga commented 7 months ago

Thanks for all the info! I will also see if I can reproduce the pattern, many regexes, large file, concurrency.

Also can you confirm the latest unreleased commit has the problem? And are you running on x86 or arm64? If you're able to verify your code still fails on the other architecture, that would also be helpful, if on an arm64 Mac, then using GOARCH=amd64 to trigger Rosetta would check it. If this is too difficult, no worries.

goingaround commented 7 months ago

still the same, but if it helps, theres the full stack

2024/04/19 20:14:38 ERROR+1 task panicked panic="wasm error: unaligned atomic\nwasm stack trace:\n\t.$189(i32)\n\t.$403(i32)\n\t.$534(i32,i32)\n\t.$795(i32,i32,i32,i32,i32,i32,i32) i32\n\t.$813(i32,i32,i32,i32,i32,i32,i32,i32) i32" stack="goroutine 53 [running]:\nruntime/debug.Stack()\n\t/opt/homebrew/opt/go/libexec/src/runtime/debug/stack.go:24 +0x64\nentro.security/detector.(*app).taskFn.func1()\n\t/Users/nitzan/go/src/entro-app/detector/app.go:196 +0x6c\npanic({0x10490de80?, 0x1401a19ae20?})\n\t/opt/homebrew/opt/go/libexec/src/runtime/panic.go:770 +0x124\ngithub.com/wasilibs/go-re2/internal.matchFrom(0x110a85060?, {0x88908?, 0x25?}, 0x696c61a1?, 0x0?, 0x0?)\n\t/Users/nitzan/go/src/entro-app/vendor/github.com/wasilibs/go-re2/internal/re2_wazero.go:328 +0x90\ngithub.com/wasilibs/go-re2/internal.(*Regexp).findAllSubmatch(0x14001a7c9c0, 0x140004f9a70, {0x696c61a1?, 0xbe938e3?}, 0xffffffffffffffff?, 0x140004f9ab0)\n\t/Users/nitzan/go/src/entro-app/vendor/github.com/wasilibs/go-re2/internal/re2.go:490 +0x100\ngithub.com/wasilibs/go-re2/internal.(*Regexp).FindAllStringSubmatch(0x14001a7c9c0, {0x14001b00000, 0xbe938e3}, 0xffffffffffffffff)\n\t/Users/nitzan/go/src/entro-app/vendor/github.com/wasilibs/go-re2/internal/re2.go:442 +0x124\nentro.security/detector/service/exposure.(*scanner).Scan(0x14001a57c08, {0x1049697c8, 0x140000120a0}, {0x14001b00000?, 0x186fa4f93be01?})\n\t/Users/nitzan/go/src/entro-app/detector/service/exposure/scanner.go:40 +0x68\nentro.security/detector.(*app).taskFn(0x14001a9e300, {0x104969838, 0x140000b04d0}, 0x14000325300)\n\t/Users/nitzan/go/src/entro-app/detector/app.go:230 +0x220\nentro.security/common/utils/task.(*taskBuilder[...]).Build.func1(0x14000325300?)\n\t/Users/nitzan/go/src/entro-app/common/utils/task/builder.go:68 +0x64\nentro.security/common/utils/task.newTask[...].func2(0x14001a9ec60?)\n\t/Users/nitzan/go/src/entro-app/common/utils/task/task.go:78 +0x9c\nentro.security/common/utils/task.(*routine[...]).run(0x104968aa0, {0x104969790, 0x14001a9ec60}, 0x14000325300)\n\t/Users/nitzan/go/src/entro-app/common/utils/task/routine.go:76 +0x100\nentro.security/common/utils/task.(*routine[...]).StartWithContext.func1()\n\t/Users/nitzan/go/src/entro-app/common/utils/task/routine.go:60 +0xf8\ncreated by entro.security/common/utils/task.(*routine[...]).StartWithContext in goroutine 5\n\t/Users/nitzan/go/src/entro-app/common/utils/task/routine.go:41 +0x190\n"
2024/04/19 20:14:38 ERROR routine has failed on execution duration=18.648667ms error="panic: wasm error: unaligned atomic\nwasm stack trace:\n\t.$189(i32)\n\t.$403(i32)\n\t.$534(i32,i32)\n\t.$795(i32,i32,i32,i32,i32,i32,i32) i32\n\t.$813(i32,i32,i32,i32,i32,i32,i32,i32) i32 [runtime.gopanic() panic.go:770]"
anuraaga commented 6 months ago

Hi @goingaround - thanks for the stack. Unfortunately still having issues reproducing but will continue to try. In the meantime, can you share what type of machine you are running on? amd64 vs arm64, # of cores, and OS? Thanks.