Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] Interface conversion bug for ipQueues in monitor which would cause panics. #4477

Merged
merged 1 commit into from Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions server/monitor.go
Expand Up @@ -1120,14 +1120,17 @@ func (s *Server) HandleIPQueuesz(w http.ResponseWriter, r *http.Request) {

queues := map[string]monitorIPQueue{}

s.ipQueues.Range(func(k, v interface{}) bool {
s.ipQueues.Range(func(k, v any) bool {
var pending, inProgress int
name := k.(string)
queue := v.(interface {
queue, ok := v.(interface {
len() int
inProgress() uint64
inProgress() int64
})
pending := queue.len()
inProgress := int(queue.inProgress())
if ok {
pending = queue.len()
inProgress = int(queue.inProgress())
}
if !all && (pending == 0 && inProgress == 0) {
return true
} else if qfilter != _EMPTY_ && !strings.Contains(name, qfilter) {
Expand Down
19 changes: 19 additions & 0 deletions server/monitor_test.go
Expand Up @@ -4981,3 +4981,22 @@ func TestHealthzStatusUnavailable(t *testing.T) {

checkHealthzEndpoint(t, s.MonitorAddr().String(), http.StatusServiceUnavailable, "unavailable")
}

// When we converted ipq to use generics we still were using sync.Map. Currently you can not convert
// interface{} or any to a generic parameterized type. So this stopped working and panics.
func TestIpqzWithGenerics(t *testing.T) {
opts := DefaultMonitorOptions()
opts.JetStream = true

s := RunServer(opts)
defer s.Shutdown()

url := fmt.Sprintf("http://%s/ipqueuesz?all=1", s.MonitorAddr().String())
body := readBody(t, url)
require_True(t, len(body) > 0)

queues := map[string]*monitorIPQueue{}
require_NoError(t, json.Unmarshal(body, &queues))
require_True(t, len(queues) >= 4)
require_True(t, queues["SendQ"] != nil)
}