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,20 +101,26 @@ 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) =>
{ {
_receiveQueue.Writer.TryWrite(new InternalSystemMessage if (_callbacks.TryGetValue(s, out var cb))
{ {
Sub = sub, _receiveQueue.Writer.TryWrite(new InternalSystemMessage
Client = SystemClient, {
Account = SystemAccount, Sub = sub,
Subject = subj, Client = SystemClient,
Reply = reply, Account = SystemAccount,
Headers = hdr, Subject = subj,
Message = msg, Reply = reply,
Callback = callback, Headers = hdr,
}); Message = msg,
Callback = cb,
});
}
}; };
SystemAccount.SubList.Insert(sub); SystemAccount.SubList.Insert(sub);