mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 18:20:42 -07:00
Merge pull request #1902 from ripienaar/leader_only
skip responses from non leaders in jsz
This commit is contained in:
@@ -1155,6 +1155,8 @@ func (s *Server) statszReq(sub *subscription, _ *client, subject, reply string,
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
var errSkipZreq = errors.New("filtered response")
|
||||
|
||||
func (s *Server) zReq(reply string, msg []byte, fOpts *EventFilterOptions, optz interface{}, respf func() (interface{}, error)) {
|
||||
if !s.EventsEnabled() || reply == _EMPTY_ {
|
||||
return
|
||||
@@ -1172,6 +1174,9 @@ func (s *Server) zReq(reply string, msg []byte, fOpts *EventFilterOptions, optz
|
||||
}
|
||||
if err == nil {
|
||||
response["data"], err = respf()
|
||||
if errors.Is(err, errSkipZreq) {
|
||||
return
|
||||
}
|
||||
status = http.StatusInternalServerError
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -2357,7 +2357,7 @@ func (s *Server) Jsz(opts *JSzOptions) (*JSInfo, error) {
|
||||
js, cc := s.getJetStreamCluster()
|
||||
if js == nil {
|
||||
// Ignore
|
||||
return nil, ErrJetStreamNotEnabled
|
||||
return nil, fmt.Errorf("%w: no cluster", errSkipZreq)
|
||||
}
|
||||
// So if we have JS but no clustering, we are the leader so allow.
|
||||
if cc != nil {
|
||||
@@ -2365,7 +2365,7 @@ func (s *Server) Jsz(opts *JSzOptions) (*JSInfo, error) {
|
||||
isLeader := cc.isLeader()
|
||||
js.mu.RUnlock()
|
||||
if !isLeader {
|
||||
return nil, errNotLeader
|
||||
return nil, fmt.Errorf("%w: not leader", errSkipZreq)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user