feat: add per-account connection/subscription limits with AccountConfig

This commit is contained in:
Joseph Doherty
2026-02-23 00:46:16 -05:00
parent cc0fe04f3c
commit 6afe11ad4d
6 changed files with 97 additions and 4 deletions

View File

@@ -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