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

[FIXED] Allow kick to work on leafnodes as well. #5587

Merged
merged 1 commit into from
Jun 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions server/leafnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7859,3 +7859,47 @@ func TestLeafNodeDupeDeliveryQueueSubAndPlainSub(t *testing.T) {
require_NoError(t, err)
require_Equal(t, n, 1)
}

func TestLeafNodeServerKickClient(t *testing.T) {
stmpl := `
listen: 127.0.0.1:-1
server_name: test-server
leaf { listen: 127.0.0.1:-1 }
`
conf := createConfFile(t, []byte(stmpl))
s, o := RunServerWithConfig(conf)
defer s.Shutdown()

tmpl := `
listen: 127.0.0.1:-1
server_name: test-leaf
leaf { remotes: [ { urls: [ nats-leaf://127.0.0.1:{LEAF_PORT} ] } ] }
`
tmpl = strings.Replace(tmpl, "{LEAF_PORT}", fmt.Sprintf("%d", o.LeafNode.Port), 1)
lConf := createConfFile(t, []byte(tmpl))
l, _ := RunServerWithConfig(lConf)
defer l.Shutdown()

checkLeafNodeConnected(t, l)

// We want to make sure we can kick the leafnode connections as well as client connections.
conns, err := s.Connz(&ConnzOptions{Account: globalAccountName})
require_NoError(t, err)
require_Equal(t, len(conns.Conns), 1)
lid := conns.Conns[0].Cid

disconnectTime := time.Now()
err = s.DisconnectClientByID(lid)
require_NoError(t, err)

// Wait until we are reconnected.
checkLeafNodeConnected(t, s)

// Look back up again and make sure start time indicates a restart, meaning kick worked.
conns, err = s.Connz(&ConnzOptions{Account: globalAccountName})
require_NoError(t, err)
require_Equal(t, len(conns.Conns), 1)
ln := conns.Conns[0]
require_True(t, lid != ln.Cid)
require_True(t, ln.Start.After(disconnectTime))
}
5 changes: 4 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4474,8 +4474,11 @@ func (s *Server) DisconnectClientByID(id uint64) error {
if client := s.getClient(id); client != nil {
client.closeConnection(Kicked)
return nil
} else if client = s.GetLeafNode(id); client != nil {
client.closeConnection(Kicked)
return nil
}
return errors.New("no such client id")
return errors.New("no such client or leafnode id")
}

// LDMClientByID sends a Lame Duck Mode info message to a client by connection ID
Expand Down