Fix races in monitoring

- Possible race/invalid value in LastActivity
- Routez
- Believe fixes #189
This commit is contained in:
Derek Collison
2016-02-06 07:09:13 -08:00
parent ddda4abbda
commit d7c8e6bca8
2 changed files with 7 additions and 2 deletions

View File

@@ -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)

View File

@@ -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