we encounter a problem with the parallel usage of sessions. It doesn't matter if it's done with `Task.WhenAll` or `Parallel.ForEach`.
After Disposing a cloned session, the session is still alive (sleeping). And it doesn't seem that those sessions are reused.
A little test-script:
async Task Main() { var connData = await DbApp.Instance.ConnectAsync(DbApp.Instance.DefaultFactory, connectionString, true)); using (var connection = connData.Connection) { var identity = connection.Authenticate(authString); using (var session = connection.Session) { //await Task.WhenAll(Enumerable.Range(0, 10).Select(i => Test(session))); Parallel.ForEach(Enumerable.Range(0, 10), i => Test2(i, session)); // all sessions are still there } // all sessions are still there } // all sessions closed } async Task Test(ISession session) { using (var s = await session.CloneAsync()) { } } void Test2(int idx, ISession session) { using (var s = session.Clone()) { } }
You can see the sessions in the database with
SELECT * FROM sys.dm_exec_sessions WHERE is_user_process = 1 AND host_name = '...'
Disposing the connection is done relatively seldom - thus I would assume that the DialogScript ADS_AssignADSGroupsToITShop is affected as well.
In the object log I see as many "Closing session"- as "Opening session"-entries - but it seems that there's no closing at all.
So the questions is: how to use session.Clone in a way, the sessions are closed/reused after usage?