{"record":{"id":"a1ea28931f774a3f","repo":"nats-io/nats-server","slug":"remote-s-cannot-be-added-at-the-moment-try-agai","errorCode":null,"errorMessage":"remote %s: cannot be added at the moment, try again","messagePattern":"remote (.+?): cannot be added at the moment, try again","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/reload.go","lineNumber":1040,"sourceCode":"\t\t\t\tcompressionChanged: !lrc.Compression.equals(&rlo.Compression),\n\t\t\t\tdisabledChanged:    disabledChanged,\n\t\t\t\topts:               rlo,\n\t\t\t}\n\t\t\tlrc.RUnlock()\n\t\t\tnlo.changed[lrc] = lnro\n\t\t}\n\t\tif len(nlo.added) > 0 {\n\t\t\t// Go through the added list and check if an added was recently removed and,\n\t\t\t// if that is the case, is it still in the `s.rmLeafRemoteCfgs` map, which\n\t\t\t// may mean that there was a connect-in-progress that did not complete yet.\n\t\t\t// Either try again (if it is the first failure) or return an error.\n\t\t\tfor _, rlo := range nlo.added {\n\t\t\t\tif _, cip := s.rmLeafRemoteCfgs[rlo.name()]; cip {\n\t\t\t\t\ts.mu.RUnlock()\n\t\t\t\t\tif failed < maxAttempts-1 {\n\t\t\t\t\t\tcontinue forLoop\n\t\t\t\t\t}\n\t\t\t\t\treturn nil, fmt.Errorf(remoteErrFormat, rlo.safeName(),\n\t\t\t\t\t\t\"cannot be added at the moment, try again\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ts.mu.RUnlock()\n\t\tbreak\n\t}\n\n\t// Now we want to make sure that there were actual changes, so that we don't\n\t// cause a reload of leafnodes for nothing. However, if one has (or all have)\n\t// been removed we still need to invoke leafNodeOption.Apply().\n\tif !nlo.tlsFirstChanged && !nlo.compressionChanged && !removed && len(nlo.added) == 0 && len(nlo.changed) == 0 {\n\t\treturn nil, nil\n\t}\n\n\treturn nlo, nil\n}\n","sourceCodeStart":1022,"sourceCodeEnd":1058,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/reload.go#L1022-L1058","documentation":"When a reload adds new leaf remotes, NATS checks whether the same remote name is still registered with a connection in progress in s.rmLeafRemoteCfgs. If so, after exhausting retries the reload fails with 'cannot be added at the moment, try again'.","triggerScenarios":"Adding a new leafnodes.remotes[] entry whose name collides with an existing remote being disconnected/reconnected (connection-in-progress flag set) during reload.","commonSituations":"Rapid config reloads where a remote was just removed and re-added; renaming URLs while keeping the same remote name on a busy connection.","solutions":["Retry the reload after the previous remote connection finishes closing.","Give the new remote a distinct name in leafnodes config to avoid the collision.","Restart the server if the add must take effect immediately and the old connection is stuck."],"exampleFix":"// before\nleafnodes { remotes: [ { name: \"r1\", url: \"nats://new:4222\" } ] } // old r1 still connecting\n// after\nleafnodes { remotes: [ { name: \"r2\", url: \"nats://new:4222\" } ] } // or reload later","handlingStrategy":"retry","validationCode":"// avoid reusing a name still disconnecting: use unique remote names\nif nameInUseDuringReload(newRemote.Name) {\n    return fmt.Errorf(\"choose a new name for remote %q\", newRemote.Name)\n}","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 3; attempt++ {\n    err := srv.Reload()\n    if err == nil || !strings.Contains(err.Error(), \"cannot be added at the moment\") {\n        break\n    }\n    time.Sleep(2 * time.Second)\n}","preventionTips":["Give each leaf remote a unique, stable name.","Wait for prior reloads/disconnects to complete before adding remotes.","Restart instead of reload when replacing a busy remote connection."],"tags":["reload","leafnodes","race-condition"],"backgroundTag":"reload-race-retry-exhausted","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}