Skip to content

Commit

Permalink
Fix JSVM and doReload race
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Dec 7, 2017
1 parent 27e8a36 commit 36dfbf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,12 @@ func rpcReloadLoop(rpcKey string) {
}
}

var reloadMu sync.Mutex

func doReload() {
reloadMu.Lock()
defer reloadMu.Unlock()

// Load the API Policies
syncPolicies()
// load the specs
Expand Down
5 changes: 5 additions & 0 deletions mw_js_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"time"

"github.com/robertkrimen/otto"
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 36dfbf1

Please sign in to comment.