Skip to content

Commit

Permalink
Merge pull request #139 from klihub/fixes/wasm-honor-context-timeouts
Browse files Browse the repository at this point in the history
adaptation: honor context deadline in WASM runtime/plugins.
  • Loading branch information
mikebrow authored Feb 5, 2025
2 parents a8b717f + e97d7ed commit 8955028
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/adaptation/adaptation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"github.com/containerd/nri/pkg/api"
"github.com/containerd/nri/pkg/log"
"github.com/containerd/ttrpc"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)

const (
Expand Down Expand Up @@ -129,7 +131,21 @@ func New(name, version string, syncFn SyncFn, updateFn UpdateFn, opts ...Option)
return nil, fmt.Errorf("failed to create NRI adaptation, nil UpdateFn")
}

wasmPlugins, err := api.NewPluginPlugin(context.Background())
wasmWithCloseOnContextDone := func(ctx context.Context) (wazero.Runtime, error) {
var (
cfg = wazero.NewRuntimeConfig().WithCloseOnContextDone(true)
r = wazero.NewRuntimeWithConfig(ctx, cfg)
)
if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil {
return nil, err
}
return r, nil
}

wasmPlugins, err := api.NewPluginPlugin(
context.Background(),
api.WazeroRuntime(wasmWithCloseOnContextDone),
)
if err != nil {
return nil, fmt.Errorf("unable to initialize WASM service: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/adaptation/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func (p *plugin) start(name, version string) (err error) {
// close a plugin shutting down its multiplexed ttrpc connections.
func (p *plugin) close() {
if p.impl.isWasm() {
p.closed = true
return
}

Expand Down

0 comments on commit 8955028

Please sign in to comment.