From d7c8e6bca8053a56f5b837e3874291bdd2045a22 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Sat, 6 Feb 2016 07:09:13 -0800 Subject: [PATCH] Fix races in monitoring - Possible race/invalid value in LastActivity - Routez - Believe fixes #189 --- server/monitor.go | 8 ++++++-- server/monitor_sort_opts.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/monitor.go b/server/monitor.go index 87800608..4bd2a7ce 100644 --- a/server/monitor.go +++ b/server/monitor.go @@ -140,12 +140,14 @@ func (s *Server) HandleConnz(w http.ResponseWriter, r *http.Request) { // For some of the fields, we need to use the values from 'cli' here, // not 'client', because otherwise we may be off compared to the // previous sort. + last := time.Unix(0, cli.last) + ci := &ConnInfo{ Cid: client.cid, Start: client.start, - LastActivity: client.last, + LastActivity: last, Uptime: myUptime(c.Now.Sub(client.start)), - Idle: myUptime(c.Now.Sub(client.last)), + Idle: myUptime(c.Now.Sub(last)), InMsgs: cli.inMsgs, OutMsgs: cli.outMsgs, InBytes: cli.inBytes, @@ -237,6 +239,7 @@ func (s *Server) HandleRoutez(w http.ResponseWriter, r *http.Request) { rs.NumRoutes = len(s.routes) for _, r := range s.routes { + r.mu.Lock() ri := &RouteInfo{ Rid: r.cid, RemoteId: r.route.remoteID, @@ -252,6 +255,7 @@ func (s *Server) HandleRoutez(w http.ResponseWriter, r *http.Request) { if subs == 1 { ri.Subs = castToSliceString(r.subs.All()) } + r.mu.Unlock() if ip, ok := r.nc.(*net.TCPConn); ok { addr := ip.RemoteAddr().(*net.TCPAddr) diff --git a/server/monitor_sort_opts.go b/server/monitor_sort_opts.go index 40de19ab..1501979c 100644 --- a/server/monitor_sort_opts.go +++ b/server/monitor_sort_opts.go @@ -21,6 +21,7 @@ const ( byIdle = "idle" ) +// FIXME(dlc) - Why have 3 structures, 1 client, 2 ClientInfo, 3 ConnInfo. type ClientInfo struct { client *client cid uint64