Skip to content

fix: prevent template dictionary memory leak in ds-atleastonce demo#42

Merged
dexcompiler merged 3 commits intodemo/ds-atleastonce-idempotency-fixesfrom
copilot/sub-pr-41
Feb 16, 2026
Merged

fix: prevent template dictionary memory leak in ds-atleastonce demo#42
dexcompiler merged 3 commits intodemo/ds-atleastonce-idempotency-fixesfrom
copilot/sub-pr-41

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 16, 2026

Code review identified a memory leak: the _templates dictionary grew unboundedly because it was never cleaned up when orders completed, negating the bounded inbox fix.

Changes

  • Template cleanup: Added removal of payment/inventory templates in HandleAck when both acks received, matching cleanup of _acks, _attempts, and _correlationIds dictionaries
  • Hardcoded strings → constants: Extracted PaymentsNodeName and InventoryNodeName constants to ensure cleanup logic stays synchronized with template creation
// Now cleans up all order-related state atomically
_acks.TryRemove(msg.OrderId, out _);
_attempts.TryRemove(msg.OrderId, out _);
_correlationIds.TryRemove(msg.OrderId, out _);
_templates.TryRemove(new LogicalMessageKey(MessageKind.PlaceOrder, msg.OrderId, PaymentsNodeName), out _);
_templates.TryRemove(new LogicalMessageKey(MessageKind.PlaceOrder, msg.OrderId, InventoryNodeName), out _);

Without this fix, long simulations would still experience unbounded growth through template accumulation despite the bounded inbox.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 16, 2026 16:48
Add cleanup of _templates dictionary in HandleAck to match cleanup of other dictionaries and prevent unbounded growth in long simulations.

Co-authored-by: dexcompiler <115876036+dexcompiler@users.noreply.github.com>
Extract "payments" and "inventory" strings to constants for better maintainability and consistency across template operations.

Co-authored-by: dexcompiler <115876036+dexcompiler@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bounded inbox dedupe and stabilize MessageId fix: prevent template dictionary memory leak in ds-atleastonce demo Feb 16, 2026
Copilot AI requested a review from dexcompiler February 16, 2026 16:53
@dexcompiler dexcompiler marked this pull request as ready for review February 16, 2026 16:54
Copy link
Copy Markdown
Owner

@dexcompiler dexcompiler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dexcompiler dexcompiler merged commit f7bc3a0 into demo/ds-atleastonce-idempotency-fixes Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants