Skip to content

Commit 8bfba08

Browse files
committed
Fix InMemoryTransactionIdStorage stale session on reconnect
Get(persistable:true) used SafeAdd which returned the cached session with old requestId mappings. When a client reconnects with the same sessionId, CreateTransactionId throws "duplicated". Replace SafeAdd with unconditional assignment to always create a fresh session.
1 parent 7085927 commit 8bfba08

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Configuration/ITransactionIdStorage.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ bool ISessionTransactionIdStorage.RemoveTransactionId(long transactionId)
142142
private readonly SynchronizedDictionary<string, ISessionTransactionIdStorage> _item = [];
143143

144144
ISessionTransactionIdStorage ITransactionIdStorage.Get(string sessionId, bool persistable)
145-
=> persistable ? _item.SafeAdd(sessionId, key => new InMemorySessionTransactionIdStorage(_idGenerator)) : new InMemorySessionTransactionIdStorage(_idGenerator);
145+
{
146+
if (!persistable)
147+
return new InMemorySessionTransactionIdStorage(_idGenerator);
148+
149+
var session = new InMemorySessionTransactionIdStorage(_idGenerator);
150+
_item[sessionId] = session;
151+
return session;
152+
}
146153
}
147154

148155
/// <summary>

0 commit comments

Comments
 (0)