feat: add per-account connection/subscription limits with AccountConfig
This commit is contained in:
@@ -372,7 +372,13 @@ public sealed class NatsClient : IDisposable
|
||||
{
|
||||
var accountName = result.AccountName ?? Account.GlobalAccountName;
|
||||
Account = server.GetOrCreateAccount(accountName);
|
||||
Account.AddClient(Id);
|
||||
if (!Account.AddClient(Id))
|
||||
{
|
||||
Account = null;
|
||||
await SendErrAndCloseAsync("maximum connections for account exceeded",
|
||||
ClientClosedReason.AuthenticationViolation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogDebug("Client {ClientId} authenticated as {Identity}", Id, result.Identity);
|
||||
@@ -386,7 +392,13 @@ public sealed class NatsClient : IDisposable
|
||||
if (Account == null && Router is NatsServer server2)
|
||||
{
|
||||
Account = server2.GetOrCreateAccount(Account.GlobalAccountName);
|
||||
Account.AddClient(Id);
|
||||
if (!Account.AddClient(Id))
|
||||
{
|
||||
Account = null;
|
||||
await SendErrAndCloseAsync("maximum connections for account exceeded",
|
||||
ClientClosedReason.AuthenticationViolation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate no_responders requires headers
|
||||
|
||||
Reference in New Issue
Block a user