Skip to content

Commit

Permalink
Fix JSVM race
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Dec 7, 2017
1 parent 4d8fa62 commit f966160
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mw_js_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"strings"
"time"
"sync"

"github.com/robertkrimen/otto"
_ "github.com/robertkrimen/otto/underscore"
Expand Down Expand Up @@ -280,6 +281,7 @@ func mapStrsToIfaces(m map[string]string) map[string]interface{} {
// --- Utility functions during startup to ensure a sane VM is present for each API Def ----

type JSVM struct {
sync.Mutex
Spec *APISpec
VM *otto.Otto
Timeout time.Duration
Expand All @@ -290,6 +292,9 @@ type JSVM struct {
// Init creates the JSVM with the core library and sets up a default
// timeout.
func (j *JSVM) Init(spec *APISpec) {
j.Lock()
defer j.Unlock()

vm := otto.New()

// Init TykJS namespace, constructors etc.
Expand Down

0 comments on commit f966160

Please sign in to comment.