Update LastActivity on connect for routes

Signed-off-by: Waldemar Quevedo <wally@nats.io>
This commit is contained in:
Waldemar Quevedo
2023-08-21 11:06:07 -07:00
parent bcf5da04e3
commit bdb874a6a8
3 changed files with 36 additions and 3 deletions

View File

@@ -1905,6 +1905,9 @@ func (s *Server) addRoute(c *client, didSolicit bool, info *Info, accName string
c.mu.Lock()
idHash := c.route.idHash
cid := c.cid
if c.last.IsZero() {
c.last = time.Now()
}
c.mu.Unlock()
// Store this route with key being the route id hash + account name
@@ -1980,10 +1983,13 @@ func (s *Server) addRoute(c *client, didSolicit bool, info *Info, accName string
rHash := c.route.hash
rn := c.route.remoteName
url := c.route.url
// For solicited routes, we need now to send the INFO protocol
// For solicited routes, we need now to send the INFO protocol.
if didSolicit {
c.enqueueProto(s.generateRouteInitialInfoJSON(_EMPTY_, c.route.compression, idx))
}
if c.last.IsZero() {
c.last = time.Now()
}
c.mu.Unlock()
// Add to the slice and bump the count of connections for this remote

View File

@@ -1153,7 +1153,18 @@ func TestRouteNoCrashOnAddingSubToRoute(t *testing.T) {
defer rs.Shutdown()
servers = append(servers, rs)
// Create a sub on each routed server
// Confirm routes are active before clients connect.
for _, srv := range servers {
rz, err := srv.Routez(nil)
require_NoError(t, err)
for i, route := range rz.Routes {
if route.LastActivity.IsZero() {
t.Errorf("Expected LastActivity to be valid (%d)", i)
}
}
}
// Create a sub on each routed server.
nc := natsConnect(t, fmt.Sprintf("nats://%s:%d", ropts.Host, ropts.Port))
defer nc.Close()
natsSub(t, nc, "foo", cb)