Skip to content

Commit

Permalink
Fix more locks
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Aug 28, 2022
1 parent 1f86cce commit ee95123
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions gateway/api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,15 @@ func (gw *Gateway) loadHTTPService(spec *APISpec, apisByListen map[string]int, g

var chainObj *ChainObject

gw.apisMu.RLock()
if curSpec, ok := gw.apisByID[spec.APIID]; ok && curSpec.Checksum == spec.Checksum {
if chain, found := gw.apisHandlesByID.Load(spec.APIID); found {
chainObj = chain.(*ChainObject)
}
} else {
chainObj = gw.processSpec(spec, apisByListen, gs, subrouter, logrus.NewEntry(log))
}
gw.apisMu.RUnlock()

if chainObj.Skip {
return chainObj
Expand Down Expand Up @@ -908,18 +910,12 @@ func (gw *Gateway) loadApps(specs []*APISpec) {
}

gw.apisMu.RLock()
for _, spec := range specs {
for _, curSpec := range gw.apisByID {
if spec.APIID == curSpec.APIID && spec.Checksum != curSpec.Checksum {
tmpSpecRegister[spec.APIID] = curSpec
}
}
}
gw.apisMu.RUnlock()

if _, found := tmpSpecRegister[spec.APIID]; !found {
if curSpec, found := gw.apisByID[spec.APIID]; found && spec.Checksum != curSpec.Checksum {
tmpSpecRegister[spec.APIID] = curSpec
} else {
tmpSpecRegister[spec.APIID] = spec
}
gw.apisMu.RUnlock()

switch spec.Protocol {
case "", "http", "https", "h2c":
Expand Down

0 comments on commit ee95123

Please sign in to comment.