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

Add timeout to create #39

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions x/wasm/keeper/vm_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package keeper

import (
"errors"
"sync"
"time"

"github.com/CosmWasm/wasmd/x/wasm/types"
wasmvm "github.com/CosmWasm/wasmvm"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
)

const CreateTimeout time.Duration = 15 * time.Second

type VMWrapper struct {
types.WasmerEngine

Expand All @@ -21,10 +25,23 @@
}
}

func (w *VMWrapper) Create(code wasmvm.WasmCode) (wasmvm.Checksum, error) {
func (w *VMWrapper) Create(code wasmvm.WasmCode) (checksum wasmvm.Checksum, err error) {
w.mu.Lock()
defer w.mu.Unlock()
return w.WasmerEngine.Create(code)
timer := time.NewTimer(CreateTimeout)
done := make(chan struct{}, 1)
go func() {
checksum, err = w.WasmerEngine.Create(code)
done <- struct{}{}
}()
Comment on lines +33 to +36

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
select {
case <-done:
timer.Stop()
return
case <-timer.C:
err = errors.New("create wasm code timed out")
return
}
}

func (w *VMWrapper) Instantiate(
Expand Down
Loading