Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM plugin error causes SIGSEGV #3758

Closed
edman opened this issue Dec 22, 2024 · 0 comments · Fixed by #3759
Closed

WASM plugin error causes SIGSEGV #3758

edman opened this issue Dec 22, 2024 · 0 comments · Fixed by #3759
Labels
bug Something isn't working

Comments

@edman
Copy link
Contributor

edman commented Dec 22, 2024

Version

1.27.0

What happened?

sqlc throws a SIGSEGV when a WASM plugin fails to load.

That's caused by https://github.com/sqlc-dev/sqlc/blob/main/internal/ext/wasm/wasm.go#L226 where sqlc calls result.Close() on a wazero module, but wazero already closes modules on error.

Relevant log output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb0 pc=0x1140027]

goroutine 8 [running]:
github.com/tetratelabs/wazero/internal/wasm.(*ModuleInstance).setExitCode(...)
        github.com/tetratelabs/[email protected]/internal/wasm/module_instance.go:142
github.com/tetratelabs/wazero/internal/wasm.(*ModuleInstance).CloseWithExitCode(0x8?, {0x1dce8a0?, 0xc00036dc20?}, 0x1?)
        github.com/tetratelabs/[email protected]/internal/wasm/module_instance.go:101 +0x27
github.com/tetratelabs/wazero/internal/wasm.(*ModuleInstance).Close(0xc0007bc090?, {0x1dce8a0?, 0xc00036dc20?})
        github.com/tetratelabs/[email protected]/internal/wasm/module_instance.go:96 +0x1f
github.com/sqlc-dev/sqlc/internal/ext/wasm.(*Runner).Invoke(0xc0009cf3c0, {0x1dce8a0, 0xc00036dc20}, {0x1aa58a8, 0x1f}, {0x19991e0?, 0xc0007fa630?}, {0x18e1f80, 0xc0009cf400}, {0x0, ...})
        github.com/sqlc-dev/sqlc/internal/ext/wasm/wasm.go:229 +0x1039
github.com/sqlc-dev/sqlc/internal/plugin.(*codegenServiceClient).Generate(0xc0005f8ad8, {0x1dce8a0, 0xc00036dc20}, 0xc0007fa630, {0x0, 0x0, 0x0})
        github.com/sqlc-dev/sqlc/internal/plugin/codegen_grpc.pb.go:42 +0xc8
github.com/sqlc-dev/sqlc/internal/cmd.codegen({_, _}, {{{0x33eb9d0, 0x1}, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...}, ...}, ...)
        github.com/sqlc-dev/sqlc/internal/cmd/generate.go:410 +0x552
github.com/sqlc-dev/sqlc/internal/cmd.(*generator).ProcessResult(_, {_, _}, {{{0x33eb9d0, 0x1}, {{0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...}, ...}, ...}, ...)
        github.com/sqlc-dev/sqlc/internal/cmd/generate.go:203 +0xa5
github.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()
        github.com/sqlc-dev/sqlc/internal/cmd/process.go:113 +0x8f0
golang.org/x/sync/errgroup.(*Group).Go.func1()
        golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x96

Database schema

NA

SQL queries

NA

Configuration

NA

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

@edman edman added the bug Something isn't working label Dec 22, 2024
kyleconroy pushed a commit that referenced this issue Dec 27, 2024
wazero takes care not to leak modules when `InstantiateModule` returns
an error.

This means that sqlc will call `result.Close` a second time if a non nil
module was returned, which causes a segfault.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant