Skip to content

Commit

Permalink
continue hunting data races
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded committed Nov 24, 2017
1 parent a83964a commit 1a924de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ session_state_gen_test.go
__pycache__/

tyk_linux_*
*.cov
3 changes: 2 additions & 1 deletion cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func getTLSConfigForClient(baseConfig *tls.Config, listenPort int) func(hello *t
return newConfig, nil
}

for _, spec := range apiSpecs {
currApiSpecs := getApiSpecs()
for _, spec := range currApiSpecs {
if spec.UseMutualTLSAuth && spec.Domain == hello.ServerName {
newConfig.ClientAuth = tls.RequireAndVerifyClientCert
certIDs := append(spec.ClientCertificates, config.Global.Security.Certificates.API...)
Expand Down
36 changes: 29 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,31 @@ func getApiSpec(apiID string) *APISpec {
return apisByID[apiID]
}

func apiSpecsLen() int {
func getApiSpecs() []*APISpec {
apisMu.RLock()
defer apisMu.RUnlock()
if apiSpecs == nil {
return nil
}
apiSpecsTmp := make([]*APISpec, len(apiSpecs))
for index, val := range apiSpecs {
apiSpecsTmp[index] = val
}
return apiSpecsTmp
}

func apisByIDLen() int {
apisMu.Lock()
defer apisMu.Unlock()
return len(apisByID)
}

func apiSpecsLen() int {
apisMu.Lock()
defer apisMu.Unlock()
return len(apiSpecs)
}

// Create all globals and init connection handlers
func setupGlobals() {
resetMainRouter()
Expand Down Expand Up @@ -631,7 +650,7 @@ func doReload() {

// skip re-loading only if dashboard service reported 0 APIs
// and current registry had 0 APIs
if len(apiSpecs) == 0 && apiSpecsLen() == 0 {
if apiSpecsLen() == 0 && apisByIDLen() == 0 {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Warning("No API Definitions found, not reloading")
Expand All @@ -657,7 +676,8 @@ func doReload() {
loadAPIEndpoints(mainRouter, &mainRouterMu)
}

loadApps(apiSpecs, mainRouter, &mainRouterMu)
currApiSpecs := getApiSpecs()
loadApps(currApiSpecs, mainRouter, &mainRouterMu)

log.WithFields(logrus.Fields{
"prefix": "main",
Expand Down Expand Up @@ -1329,8 +1349,9 @@ func listen(l, controlListener net.Listener, err error) {

if atomic.LoadUint32(&rpcEmergencyMode) == 0 {
syncAPISpecs()
if apiSpecs != nil {
loadApps(apiSpecs, mainRouter, &mainRouterMu)
currApiSpecs := getApiSpecs()
if currApiSpecs != nil {
loadApps(currApiSpecs, mainRouter, &mainRouterMu)
syncPolicies()
}

Expand Down Expand Up @@ -1405,8 +1426,9 @@ func listen(l, controlListener net.Listener, err error) {
// Resume accepting connections in a new goroutine.
if atomic.LoadUint32(&rpcEmergencyMode) == 0 {
syncAPISpecs()
if apiSpecs != nil {
loadApps(apiSpecs, mainRouter, &mainRouterMu)
currApiSpecs := getApiSpecs()
if currApiSpecs != nil {
loadApps(currApiSpecs, mainRouter, &mainRouterMu)
syncPolicies()
}

Expand Down

0 comments on commit 1a924de

Please sign in to comment.