Skip to content

Commit

Permalink
fix: Use fresh instance on each new plugin invocation (#413)
Browse files Browse the repository at this point in the history
* fix: Use fresh instance on each new plugin invocation

* Skip test that depends on 1password page html, see #414

* Pass in instance we want to close to deferred function

---------

Co-authored-by: Gabor Javorszky <[email protected]>
  • Loading branch information
ospencer and javorszky authored Apr 5, 2023
1 parent 79d21dd commit 2b957b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions sat/engine2/enginetest/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func TestEngineSetRespHeader(t *testing.T) {
}

func TestEngineFetch(t *testing.T) {
t.Skip("This test gets skipped until https://github.com/suborbital/e2core/issues/414 is resolved")

ref, err := engine2.WasmRefFromFile("./testdata/fetch/fetch.wasm")
if err != nil {
t.Error(err)
Expand Down
15 changes: 11 additions & 4 deletions sat/engine2/runtime/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,21 @@ func (ip *InstancePool) RemoveInstance() error {

// UseInstance provides an instance from the environment's pool to be used by a callback function
func (ip *InstancePool) UseInstance(ctx *scheduler.Ctx, instFunc func(*instance.Instance, int32)) error {
// grab an instance from the available queue and then
// return it to the environment when finished
// grab an instance from the available queue
inst := <-ip.availableInstances

defer func() {
ip.availableInstances <- inst
go func() {
// prepare a new instance
if err := ip.AddInstance(); err != nil {
panic(err)
}
}()

defer func(it *instance.Instance) {
it.Close()
it = nil
}(inst)

// generate a random identifier as a reference to the instance in use to
// easily allow the Wasm module to reference itself when calling back over the FFI
ident, err := instance.Store(inst)
Expand Down

0 comments on commit 2b957b1

Please sign in to comment.