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

Fix for stream imports and leafnodes, fixes #1332 #1335

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,8 @@ func (c *client) addShadowSub(sub *subscription, im *streamImport, useFrom bool)

// Update our route map here.
c.srv.updateRouteSubscriptionMap(im.acc, &nsub, 1)
c.srv.updateLeafNodes(im.acc, &nsub, 1)

return &nsub, nil
}

Expand Down
79 changes: 79 additions & 0 deletions test/leafnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3228,3 +3228,82 @@ func TestClusterTLSMixedIPAndDNS(t *testing.T) {
// Make sure this works.
checkLeafNodeConnected(t, srvA)
}

// This will test for a bug in stream export/import with leafnodes.
// https://github.com/nats-io/nats-server/issues/1332
func TestStreamExportWithMultipleAccounts(t *testing.T) {
confA := createConfFile(t, []byte(`
listen: 127.0.0.1:-1
leafnodes {
listen: "127.0.0.1:-1"
}
`))
srvA, optsA := RunServerWithConfig(confA)
defer srvA.Shutdown()

bConfigTemplate := `
listen: 127.0.0.1:-1
leafnodes {
listen: "127.0.0.1:-1"
remotes = [
{
url:"nats://127.0.0.1:%d"
account:"EXTERNAL"
}
]
}
accounts: {
INTERNAL: {
users: [
{user: good, password: pwd}
]
imports: [
{
stream: {
account: EXTERNAL
subject: "foo"
}
}
]
},
EXTERNAL: {
users: [
{user: bad, password: pwd}
]
exports: [{stream: "foo"}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it "fun" maybe you could have made the export "bar" and then publish on "bar" and make sure it is received (on "foo"). This will make sure that the LS+ is sent on "bar" and not ">" (or "foo"), no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean remap the foo on import with a prefix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be on prefix + "foo" for streams. But will add that to make sure we do prefix subj.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought that we were mapping.. for stream there is only prefix..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, test a service too?

},
}
`

confB := createConfFile(t, []byte(fmt.Sprintf(bConfigTemplate, optsA.LeafNode.Port)))
srvB, optsB := RunServerWithConfig(confB)
defer srvB.Shutdown()

nc, err := nats.Connect(fmt.Sprintf("nats://good:pwd@%s:%d", optsB.Host, optsB.Port))
if err != nil {
t.Fatalf("Error on connect: %v", err)
}
defer nc.Close()

wcsub, err := nc.SubscribeSync(">")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
defer wcsub.Unsubscribe()
nc.Flush()

nc2, err := nats.Connect(fmt.Sprintf("nats://%s:%d", optsA.Host, optsA.Port))
if err != nil {
t.Fatalf("Error on connect: %v", err)
}
defer nc2.Close()

nc2.Publish("foo", nil)

checkFor(t, 250*time.Millisecond, 10*time.Millisecond, func() error {
if nmsgs, _, err := wcsub.Pending(); err != nil || nmsgs != 1 {
return fmt.Errorf("Did not receive the message: %v", err)
}
return nil
})
}