4 Commits

Author SHA1 Message Date
mayuresh82
d39e46096f Merge pull request #11 from mayuresh82/deadlock_fix
fix the deadlock
2021-10-20 11:23:51 -07:00
Mayuresh Gaitonde
a99f92e9a5 fix 2021-10-18 18:21:01 -07:00
Mayuresh Gaitonde
5ac02c373b dockerfile fix 2021-10-18 18:16:22 -07:00
Mayuresh Gaitonde
6fdff28716 fix the deadlock 2021-10-18 15:50:13 -07:00
3 changed files with 14 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
FROM golang:alpine as builder
FROM golang:1.14-alpine as builder
RUN apk update && \
apk upgrade && \
apk add --no-cache git && \

View File

@@ -69,7 +69,8 @@ type MonitorMgr struct {
ctrl *Controller
consul *ConsulMon
sync.Mutex
monMu sync.Mutex
clMu sync.Mutex
}
func NewMonitor(config *c.Config) *MonitorMgr {
@@ -123,7 +124,7 @@ func (m *MonitorMgr) consulMon() {
}
// remove currently running apps that are not discovered in this pass
var toRemove []string
m.Lock()
m.monMu.Lock()
for name, mon := range m.monitors {
if mon.app.Source != "consul" {
continue
@@ -140,10 +141,10 @@ func (m *MonitorMgr) consulMon() {
toRemove = append(toRemove, name)
}
}
m.monMu.Unlock()
for _, tr := range toRemove {
m.Remove(tr)
}
m.Unlock()
}
<-time.After(m.config.Agent.ConsulQueryInterval)
}
@@ -152,18 +153,20 @@ func (m *MonitorMgr) consulMon() {
// Add adds a new app into monitor manager
func (m *MonitorMgr) Add(app *App) {
// check if already running
m.Lock()
defer m.Unlock()
m.monMu.Lock()
for _, appMon := range m.monitors {
if appMon.app.Equal(app) && appMon.checkOn {
glog.V(2).Infof("App %s already exists", app.Name)
m.monMu.Unlock()
return
}
if appMon.app.Vip.Net.String() == app.Vip.Net.String() && appMon.app.Name != app.Name {
glog.Errorf("Error: Vip %s is already being announced by app: %s", app.Vip.Net.String(), appMon.app.Name)
m.monMu.Unlock()
return
}
}
m.monMu.Unlock()
m.Remove(app.Name)
appMon := &appMon{app: app, done: make(chan bool)}
m.monitors[app.Name] = appMon
@@ -174,6 +177,8 @@ func (m *MonitorMgr) Add(app *App) {
// Remove removes an app from monitor manager, stops BGP
/// announcement and cleans up state
func (m *MonitorMgr) Remove(appName string) {
m.monMu.Lock()
defer m.monMu.Unlock()
if a, ok := m.monitors[appName]; ok {
if a.checkOn {
a.done <- true
@@ -223,8 +228,8 @@ func (m *MonitorMgr) runMonitors(app *App) bool {
func (m *MonitorMgr) checkCond(am *appMon) error {
app := am.app
m.Lock()
defer m.Unlock()
m.clMu.Lock()
defer m.clMu.Unlock()
if m.runMonitors(app) {
glog.V(2).Infof("All Monitors for app: %s succeeded", app.Name)
if !am.announced {
@@ -246,6 +251,7 @@ func (m *MonitorMgr) checkCond(am *appMon) error {
am.announced = true
if exit, ok := m.cleanups[app.Name]; ok {
exit <- true
delete(m.cleanups, app.Name)
}
}
} else {
@@ -313,9 +319,7 @@ func (m *MonitorMgr) Cleanup(app string, exit chan bool) {
select {
case <-t.C:
glog.Infof("Cleaning up app %s", app)
m.Lock()
m.Remove(app)
m.Unlock()
case <-exit:
return
}

View File

@@ -68,9 +68,7 @@ func (s *Server) unregisterHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Invalid request, need app name specified", http.StatusBadRequest)
return
}
s.mon.Lock()
s.mon.Remove(appName[0])
s.mon.Unlock()
}
func (s *Server) infoHandler(w http.ResponseWriter, r *http.Request) {