mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-16 19:14:41 -07:00
Merge pull request #197 from nats-io/monitor_race
Fix races in monitoring
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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{})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user