Unify subscription channel overflow defaults#1181
Conversation
NatsClient and the DI builder forced SubPendingChannelFullMode to Wait, while NatsConnection defaulted to DropNewest, so overflow behavior differed by entry point. Wait applies backpressure to the socket read loop and risks the server disconnecting the client as a slow consumer. Make all entry points inherit the NatsOpts default DropNewest and raise SubPendingChannelCapacity from 1024 to 16384 so overflow stays rare. Drop the now-redundant pending parameter from the NatsClient(NatsOpts) constructor. Breaking for NatsClient and DI users under sustained overload: messages are dropped (surfaced via MessageDropped) instead of blocking.
|
Claude finished @mtmk's task in 2m 35s —— View job PR Review: Unify subscription channel overflow defaultsTasks:
ReviewThe motivation is sound: Correctness No bugs found. The mechanics are correct:
Breaking change (expected for v3.0) Removing the Capacity bump: 1 024 → 16 384 (16×)
Doc example ( SubPendingChannelFullMode = BoundedChannelFullMode.DropNewest,This is redundant (it matches the new default), but it's intentionally illustrative — showing that the field is the correct place to set the policy. Fine as-is. Test coverage All assertions updated correctly. The renamed test Overall: Clean and correct. No functional issues. The PR achieves consistent behavior across all entry points, eliminates a latent footgun, and documents the behavioral change clearly. |
All entry points now share one subscriber-channel overflow policy. NatsClient and the DI builder previously forced Wait while NatsConnection used DropNewest; Wait can stall the socket read loop and get the client disconnected as a slow consumer. They now inherit the NatsOpts default DropNewest, and the default channel capacity goes from 1024 to 16384 so overflow stays rare. Breaking for NatsClient and DI users under sustained overload: newest messages are dropped (surfaced via MessageDropped) instead of blocking.
Fixes #1161