Merge pull request #197 from nats-io/monitor_race

Fix races in monitoring
This commit is contained in:
Derek Collison
2016-02-06 07:46:09 -08:00
4 changed files with 10 additions and 5 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

View File

@@ -12,7 +12,7 @@ func TestSimpleGoServerShutdown(t *testing.T) {
base := runtime.NumGoroutine()
s := RunDefaultServer()
s.Shutdown()
time.Sleep(10 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
delta := (runtime.NumGoroutine() - base)
if delta > 1 {
t.Fatalf("%d Go routines still exist post Shutdown()", delta)
@@ -27,7 +27,7 @@ func TestGoServerShutdownWithClients(t *testing.T) {
}
s.Shutdown()
// Wait longer for client connections
time.Sleep(500 * time.Millisecond)
time.Sleep(1 * time.Second)
delta := (runtime.NumGoroutine() - base)
// There may be some finalizers or IO, but in general more than
// 2 as a delta represents a problem.

View File

@@ -335,7 +335,7 @@ var expBuf = make([]byte, 32768)
// Test result from server against regexp
func expectResult(t tLogger, c net.Conn, re *regexp.Regexp) []byte {
// Wait for commands to be processed and results queued for read
c.SetReadDeadline(time.Now().Add(1 * time.Second))
c.SetReadDeadline(time.Now().Add(2 * time.Second))
n, err := c.Read(expBuf)
c.SetReadDeadline(time.Time{})