Skip to content

WASM plugin error causes SIGSEGV #3758

Closed
@edman

Description

@edman

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/wazero@v1.7.3/internal/wasm/module_instance.go:142
github.com/tetratelabs/wazero/internal/wasm.(*ModuleInstance).CloseWithExitCode(0x8?, {0x1dce8a0?, 0xc00036dc20?}, 0x1?)
        github.com/tetratelabs/wazero@v1.7.3/internal/wasm/module_instance.go:101 +0x27
github.com/tetratelabs/wazero/internal/wasm.(*ModuleInstance).Close(0xc0007bc090?, {0x1dce8a0?, 0xc00036dc20?})
        github.com/tetratelabs/wazero@v1.7.3/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/sync@v0.8.0/errgroup/errgroup.go:78 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        golang.org/x/sync@v0.8.0/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions