mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 11:24:44 -07:00
[fixing] leafnode missing retry and service export interest propagation (#2288)
* [fixing] leafnode missing retry and service export interest propagation A missing account on initial connect attempt caused the leaf node connection to never be established. An account service import subscription was not propagated along leaf node connections. Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
@@ -1846,9 +1846,16 @@ func (a *Account) addServiceImportSub(si *serviceImport) error {
|
||||
cb := func(sub *subscription, c *client, subject, reply string, msg []byte) {
|
||||
c.processServiceImport(si, a, msg)
|
||||
}
|
||||
_, err := c.processSubEx([]byte(subject), nil, []byte(sid), cb, true, true, false)
|
||||
|
||||
return err
|
||||
sub, err := c.processSubEx([]byte(subject), nil, []byte(sid), cb, true, true, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Leafnodes introduce a new way to introduce messages into the system. Therefore forward import subscription
|
||||
// This is similar to what initLeafNodeSmapAndSendSubs does
|
||||
// TODO we need to consider performing this update as we get client subscriptions.
|
||||
// This behavior would result in subscription propagation only where actually used.
|
||||
a.srv.updateLeafNodes(a, sub, 1)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove all the subscriptions associated with service imports.
|
||||
|
||||
@@ -797,7 +797,6 @@ func (s *Server) createLeafNode(conn net.Conn, rURL *url.URL, remote *leafNodeCf
|
||||
var acc *Account
|
||||
var remoteSuffix string
|
||||
if remote != nil {
|
||||
// TODO: Decide what should be the optimal behavior here.
|
||||
// For now, if lookup fails, we will constantly try
|
||||
// to recreate this LN connection.
|
||||
|
||||
@@ -813,8 +812,12 @@ func (s *Server) createLeafNode(conn net.Conn, rURL *url.URL, remote *leafNodeCf
|
||||
var err error
|
||||
acc, err = s.LookupAccount(lacc)
|
||||
if err != nil {
|
||||
s.Errorf("No local account %q for leafnode: %v", lacc, err)
|
||||
// An account not existing is something that can happen with nats/http account resolver and the account
|
||||
// has not yet been pushed, or the request failed for other reasons.
|
||||
// remote needs to be set or retry won't happen
|
||||
c.leaf.remote = remote
|
||||
c.closeConnection(MissingAccount)
|
||||
s.Errorf("Unable to lookup account %s for solicited leafnode connection: %v", lacc, err)
|
||||
return nil
|
||||
}
|
||||
remoteSuffix = fmt.Sprintf(" for account: %s", acc.traceLabel())
|
||||
|
||||
@@ -388,13 +388,15 @@ func TestLeafNodeAccountNotFound(t *testing.T) {
|
||||
// Wait for report of error
|
||||
select {
|
||||
case e := <-l.errCh:
|
||||
if !strings.Contains(e, "No local account") {
|
||||
if !strings.Contains(e, "Unable to lookup account") {
|
||||
t.Fatalf("Expected error about no local account, got %s", e)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatalf("Did not get the error")
|
||||
}
|
||||
|
||||
// TODO below test is bogus. Instead add the account, do a reload, and make sure the connection works.
|
||||
|
||||
// For now, sa would try to recreate the connection for ever.
|
||||
// Check that lid is increasing...
|
||||
checkFor(t, 2*time.Second, 100*time.Millisecond, func() error {
|
||||
|
||||
Reference in New Issue
Block a user