mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
[FIX] Data race when setting up service import subscriptions. (#4068)
Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
@@ -2017,7 +2017,14 @@ func (a *Account) removeAllServiceImportSubs() {
|
||||
|
||||
// Add in subscriptions for all registered service imports.
|
||||
func (a *Account) addAllServiceImportSubs() {
|
||||
var sis [32]*serviceImport
|
||||
serviceImports := sis[:0]
|
||||
a.mu.RLock()
|
||||
for _, si := range a.imports.services {
|
||||
serviceImports = append(serviceImports, si)
|
||||
}
|
||||
a.mu.RUnlock()
|
||||
for _, si := range serviceImports {
|
||||
a.addServiceImportSub(si)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1594,13 +1594,23 @@ func (s *Server) fetchAccount(name string) (*Account, error) {
|
||||
}
|
||||
// The sub imports may have been setup but will not have had their
|
||||
// subscriptions properly setup. Do that here.
|
||||
var needImportSubs bool
|
||||
|
||||
acc.mu.Lock()
|
||||
if len(acc.imports.services) > 0 {
|
||||
if acc.ic == nil {
|
||||
acc.ic = s.createInternalAccountClient()
|
||||
acc.ic.acc = acc
|
||||
}
|
||||
needImportSubs = true
|
||||
}
|
||||
acc.mu.Unlock()
|
||||
|
||||
// Do these outside the lock.
|
||||
if needImportSubs {
|
||||
acc.addAllServiceImportSubs()
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user