fix: use per-SID callback dictionary in SysSubscribe to support multiple subscriptions

This commit is contained in:
Joseph Doherty
2026-02-23 05:38:10 -05:00
parent 8e790445f4
commit 89465450a1

View File

@@ -58,6 +58,7 @@ public sealed class InternalEventSystem : IAsyncDisposable
private ulong _sequence; private ulong _sequence;
private int _subscriptionId; private int _subscriptionId;
private readonly ConcurrentDictionary<string, SystemMessageHandler> _callbacks = new();
public Account SystemAccount { get; } public Account SystemAccount { get; }
public InternalClient SystemClient { get; } public InternalClient SystemClient { get; }
@@ -100,8 +101,13 @@ public sealed class InternalEventSystem : IAsyncDisposable
Client = SystemClient, Client = SystemClient,
}; };
// Wrap callback in noInlineCallback pattern: enqueue to receive loop // Store callback keyed by SID so multiple subscriptions work
_callbacks[sid] = callback;
// Set a single routing callback on the system client that dispatches by SID
SystemClient.MessageCallback = (subj, s, reply, hdr, msg) => SystemClient.MessageCallback = (subj, s, reply, hdr, msg) =>
{
if (_callbacks.TryGetValue(s, out var cb))
{ {
_receiveQueue.Writer.TryWrite(new InternalSystemMessage _receiveQueue.Writer.TryWrite(new InternalSystemMessage
{ {
@@ -112,8 +118,9 @@ public sealed class InternalEventSystem : IAsyncDisposable
Reply = reply, Reply = reply,
Headers = hdr, Headers = hdr,
Message = msg, Message = msg,
Callback = callback, Callback = cb,
}); });
}
}; };
SystemAccount.SubList.Insert(sub); SystemAccount.SubList.Insert(sub);