mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Update LastActivity on connect for routes
Signed-off-by: Waldemar Quevedo <wally@nats.io>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -183,9 +183,14 @@ func TestSeedSolicitWorks(t *testing.T) {
|
||||
// Wait for a bit for graph to connect
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Grab Routez from monitor ports, make sure we are fully connected
|
||||
// Grab Routez from monitor ports, make sure we are fully connected.
|
||||
url := fmt.Sprintf("http://%s:%d/", opts.Host, opts.HTTPPort)
|
||||
rz := readHTTPRoutez(t, url)
|
||||
for _, route := range rz.Routes {
|
||||
if route.LastActivity.IsZero() {
|
||||
t.Error("Expected LastActivity to be valid\n")
|
||||
}
|
||||
}
|
||||
ris := expectRids(t, rz, []string{s2.ID(), s3.ID()})
|
||||
if ris[s2.ID()].IsConfigured {
|
||||
t.Fatalf("Expected server not to be configured\n")
|
||||
@@ -194,8 +199,14 @@ func TestSeedSolicitWorks(t *testing.T) {
|
||||
t.Fatalf("Expected server not to be configured\n")
|
||||
}
|
||||
|
||||
// Server 2 did solicit routes to Server 1.
|
||||
url = fmt.Sprintf("http://%s:%d/", s2Opts.Host, s2Opts.HTTPPort)
|
||||
rz = readHTTPRoutez(t, url)
|
||||
for _, route := range rz.Routes {
|
||||
if route.LastActivity.IsZero() {
|
||||
t.Error("Expected LastActivity to be valid")
|
||||
}
|
||||
}
|
||||
ris = expectRids(t, rz, []string{s1.ID(), s3.ID()})
|
||||
if !ris[s1.ID()].IsConfigured {
|
||||
t.Fatalf("Expected seed server to be configured\n")
|
||||
@@ -206,6 +217,11 @@ func TestSeedSolicitWorks(t *testing.T) {
|
||||
|
||||
url = fmt.Sprintf("http://%s:%d/", s3Opts.Host, s3Opts.HTTPPort)
|
||||
rz = readHTTPRoutez(t, url)
|
||||
for _, route := range rz.Routes {
|
||||
if route.LastActivity.IsZero() {
|
||||
t.Error("Expected LastActivity to be valid")
|
||||
}
|
||||
}
|
||||
ris = expectRids(t, rz, []string{s1.ID(), s2.ID()})
|
||||
if !ris[s1.ID()].IsConfigured {
|
||||
t.Fatalf("Expected seed server to be configured\n")
|
||||
|
||||
Reference in New Issue
Block a user