diff --git a/cli/server_watch_js_command.go b/cli/server_watch_js_command.go index 84fbd351..d0b7d6db 100644 --- a/cli/server_watch_js_command.go +++ b/cli/server_watch_js_command.go @@ -90,14 +90,28 @@ func (c *SrvWatchJSCmd) updateSizes() error { return nil } +func (c *SrvWatchJSCmd) prePing(nc *nats.Conn, h nats.MsgHandler) { + sub, err := nc.Subscribe(nc.NewRespInbox(), h) + if err != nil { + return + } + + time.AfterFunc(2*time.Second, func() { sub.Unsubscribe() }) + + msg := nats.NewMsg("$SYS.REQ.SERVER.PING") + msg.Reply = sub.Subject + nc.PublishMsg(msg) +} + func (c *SrvWatchJSCmd) jetstreamAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return err } - _, err = nc.Subscribe("$SYS.SERVER.*.STATSZ", c.handle) + c.prePing(nc, c.handle) + _, err = nc.Subscribe("$SYS.SERVER.*.STATSZ", c.handle) if err != nil { return err } diff --git a/cli/server_watch_srv_command.go b/cli/server_watch_srv_command.go index add91721..357a61ee 100644 --- a/cli/server_watch_srv_command.go +++ b/cli/server_watch_srv_command.go @@ -95,12 +95,28 @@ func (c *SrvWatchServerCmd) updateSizes() error { return nil } + +func (c *SrvWatchServerCmd) prePing(nc *nats.Conn, h nats.MsgHandler) { + sub, err := nc.Subscribe(nc.NewRespInbox(), h) + if err != nil { + return + } + + time.AfterFunc(2*time.Second, func() { sub.Unsubscribe() }) + + msg := nats.NewMsg("$SYS.REQ.SERVER.PING") + msg.Reply = sub.Subject + nc.PublishMsg(msg) +} + func (c *SrvWatchServerCmd) serversAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return err } + c.prePing(nc, c.handle) + _, err = nc.Subscribe("$SYS.SERVER.*.STATSZ", c.handle) if err != nil {