skips jsz on non js machines when leader only requested

This is a regression introduced in 055703f4fa
that leads to panics in management tooling

Signed-off-by: R.I.Pienaar <rip@devco.net>
This commit is contained in:
R.I.Pienaar
2022-03-31 12:02:09 +02:00
parent d634d237ca
commit 4c4aa3e87f
2 changed files with 30 additions and 0 deletions

View File

@@ -2617,6 +2617,10 @@ func (s *Server) Jsz(opts *JSzOptions) (*JSInfo, error) {
js := s.getJetStream()
if js == nil || !js.isEnabled() {
if opts.LeaderOnly {
return nil, fmt.Errorf("%w: not leader", errSkipZreq)
}
jsi.Disabled = true
return jsi, nil
}

View File

@@ -17,6 +17,7 @@ import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/rand"
@@ -3980,6 +3981,31 @@ func checkForJSClusterUp(t *testing.T, servers ...*Server) {
})
}
func TestMonitorJszNonJszServer(t *testing.T) {
srv := RunServer(DefaultOptions())
defer srv.Shutdown()
if !srv.ReadyForConnections(5 * time.Second) {
t.Fatalf("server did not become ready")
}
jsi, err := srv.Jsz(&JSzOptions{})
if err != nil {
t.Fatalf("jsi failed: %v", err)
}
if jsi.ID != srv.ID() {
t.Fatalf("did not receive valid info")
}
jsi, err = srv.Jsz(&JSzOptions{LeaderOnly: true})
if !errors.Is(err, errSkipZreq) {
t.Fatalf("expected a skip z req error: %v", err)
}
if jsi != nil {
t.Fatalf("expected no jsi: %v", jsi)
}
}
func TestMonitorJsz(t *testing.T) {
readJsInfo := func(url string) *JSInfo {
t.Helper()