Skip to content

Commit

Permalink
Merge pull request #3538 from nats-io/fix_import_own_export
Browse files Browse the repository at this point in the history
[FIXED] Stack overflow when account imports its own export
  • Loading branch information
kozlovic committed Oct 10, 2022
2 parents d9bf82b + c3adf78 commit cf71adb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
30 changes: 30 additions & 0 deletions server/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3587,3 +3587,33 @@ func TestAccountImportCycle(t *testing.T) {
require_NoError(t, err)
req()
}

func TestAccountImportOwnExport(t *testing.T) {
conf := createConfFile(t, []byte(`
port: -1
accounts: {
A: {
exports: [
{ service: echo, accounts: [A], latency: { subject: "latency.echo" } }
],
imports: [
{ service: { account: A, subject: echo } }
]
users: [
{ user: user, pass: pass }
]
}
}
`))
defer removeFile(t, conf)
s, _ := RunServerWithConfig(conf)
defer s.Shutdown()

nc := natsConnect(t, s.ClientURL(), nats.UserInfo("user", "pass"))
defer nc.Close()

natsSub(t, nc, "echo", func(m *nats.Msg) { m.Respond(nil) })
_, err := nc.Request("echo", []byte("request"), time.Second)
require_NoError(t, err)
}
5 changes: 2 additions & 3 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3847,9 +3847,8 @@ func (c *client) processServiceImport(si *serviceImport, acc *Account, msg []byt
if (c.kind == GATEWAY || c.kind == ROUTER) && !isResponse {
return
}
// If we are here and we are a serviceImport response make sure we are not matching back
// to the import/export pair that started the request. If so ignore.
if isResponse && len(c.pa.psi) > 0 {
// Detect cycles and ignore (return) when we detect one.
if len(c.pa.psi) > 0 {
for i := len(c.pa.psi) - 1; i >= 0; i-- {
if psi := c.pa.psi[i]; psi.se == si.se {
return
Expand Down

0 comments on commit cf71adb

Please sign in to comment.