Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LastActivity on connect for routes #4415

Merged
merged 1 commit into from Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion server/route.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion server/routes_test.go
Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion test/route_discovery_test.go
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down