diff --git a/main.go b/main.go index 7638977f98b..ea888822d13 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/mw_js_plugin.go b/mw_js_plugin.go index e14079f8c62..1aa249c6442 100644 --- a/mw_js_plugin.go +++ b/mw_js_plugin.go @@ -12,6 +12,7 @@ import ( "os" "path/filepath" "strings" + "sync" "time" "github.com/robertkrimen/otto" @@ -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 @@ -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.