Skip to content

Commit 5ad3153

Browse files
committed
[FIXED] Monitoring: Issue with Connz filters "cid" and "state=all"
When filtering on a given connection ID, if the user also filters on the state being "all" and the connection is opened, it would not be returned. It would be if the connection was closed. Resolves #6839 Signed-off-by: Ivan Kozlovic <[email protected]>
1 parent 93f015f commit 5ad3153

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

server/monitor.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,17 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {
340340

341341
// Search by individual CID.
342342
if cid > 0 {
343-
if state == ConnClosed || state == ConnAll {
343+
// Let's first check if user also selects on ConnOpen or ConnAll
344+
// and look for opened connections.
345+
if state == ConnOpen || state == ConnAll {
346+
if client := s.clients[cid]; client != nil {
347+
openClients = append(openClients, client)
348+
closedClients = nil
349+
}
350+
}
351+
// If we did not find, and the user selected for ConnClosed or ConnAll,
352+
// look for closed connections.
353+
if len(openClients) == 0 && (state == ConnClosed || state == ConnAll) {
344354
copyClosed := closedClients
345355
closedClients = nil
346356
for _, cc := range copyClosed {
@@ -349,11 +359,6 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {
349359
break
350360
}
351361
}
352-
} else if state == ConnOpen || state == ConnAll {
353-
client := s.clients[cid]
354-
if client != nil {
355-
openClients = append(openClients, client)
356-
}
357362
}
358363
} else {
359364
// Gather all open clients.

server/monitor_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,12 @@ func TestMonitorConnzWithStateForClosedConns(t *testing.T) {
19491949
if lc := len(c.Conns); lc != 1 {
19501950
return fmt.Errorf("Expected a connection in open array, got %d", lc)
19511951
}
1952+
// It should also work if we ask for "state=all"
1953+
c = pollConnz(t, s, mode, url+"connz?cid=2&state=all", &ConnzOptions{CID: 2, State: ConnAll})
1954+
if lc := len(c.Conns); lc != 1 {
1955+
return fmt.Errorf("Expected a connection in open array, got %d", lc)
1956+
}
1957+
// But not for "state=closed"
19521958
c = pollConnz(t, s, mode, url+"connz?cid=2&state=closed", &ConnzOptions{CID: 2, State: ConnClosed})
19531959
if lc := len(c.Conns); lc != 0 {
19541960
return fmt.Errorf("Expected no connections in closed array, got %d", lc)

0 commit comments

Comments
 (0)