fix(gateway): bound the session replay ring by bytes as well as count (mxaccessgw#172)
The replay ring was bounded only by ReplayBufferCapacity (1024 events) and ReplayRetentionSeconds. Event size is unbounded up to the worker frame size, so a burst of large-array events could pin gigabytes per session while the count looked small. New MxGateway:Events:ReplayBufferMaxBytes (default 64 MiB, 0 disables) caps the summed serialized size (MxEvent.CalculateSize, measured only when the cap is on). Over the cap the oldest entries are evicted, exactly like the count cap, so a resuming subscriber sees the existing ReplayGap path; an event bigger than the whole cap is not retained. Every eviction (count, age or byte) now clears its slot, so an evicted event is released immediately instead of staying referenced until the slot is reused. The 64 MiB default is a judgement call: it never binds for scalar traffic (1024 x a few hundred bytes) and only trims large-array bursts. Tests: SessionEventDistributorTests byte-cap eviction, single oversized event, cap 0 = count only (the first two fail with the cap enforcement removed); validator rejects a negative value. Docs: GatewayConfiguration.md, Sessions.md, DesignDecisions.md; appsettings.json carries the key. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -121,6 +121,7 @@ public sealed class GatewayOptionsTests
|
||||
[InlineData("MxGateway:Sessions:LeaseSweepIntervalSeconds", "0", "MxGateway:Sessions:LeaseSweepIntervalSeconds must be greater than zero.")]
|
||||
[InlineData("MxGateway:Sessions:DetachGraceSeconds", "-1", "MxGateway:Sessions:DetachGraceSeconds must be zero or greater (0 disables detach-grace retention).")]
|
||||
[InlineData("MxGateway:Sessions:WorkerReadyWaitTimeoutMs", "-1", "MxGateway:Sessions:WorkerReadyWaitTimeoutMs must be greater than or equal to zero.")]
|
||||
[InlineData("MxGateway:Events:ReplayBufferMaxBytes", "-1", "MxGateway:Events:ReplayBufferMaxBytes must be greater than or equal to zero.")]
|
||||
[InlineData("MxGateway:Events:QueueCapacity", "0", "MxGateway:Events:QueueCapacity must be greater than zero.")]
|
||||
[InlineData("MxGateway:Protocol:MaxGrpcMessageBytes", "0", "MxGateway:Protocol:MaxGrpcMessageBytes must be between")]
|
||||
[InlineData("MxGateway:Authentication:PepperSecretName", "", "MxGateway:Authentication:PepperSecretName is required")]
|
||||
|
||||
Reference in New Issue
Block a user