Skip to content

Commit f5d3372

Browse files
committed
Fix hinding exception & StackTrace in OpenSessionInternalAsync()
1 parent d1e4da8 commit f5d3372

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Orm/Xtensive.Orm/Orm/Domain.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Collections.Concurrent;
99
using System.Collections.Generic;
10+
using System.Runtime.ExceptionServices;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213
using JetBrains.Annotations;
@@ -346,19 +347,28 @@ internal async Task<Session> OpenSessionInternalAsync(SessionConfiguration confi
346347
// That would make session accessible for user before
347348
// connection become opened.
348349
session = new Session(this, storageNode, configuration, false);
350+
ExceptionDispatchInfo exceptionDispatchInfo = null;
349351
try {
350352
await ((SqlSessionHandler) session.Handler).OpenConnectionAsync(cancellationToken)
351353
.ContinueWith(t => {
352-
if (sessionScope != null) {
353-
session.AttachToScope(sessionScope);
354+
if (t.Status == TaskStatus.RanToCompletion) {
355+
if (sessionScope != null) {
356+
session.AttachToScope(sessionScope);
357+
}
354358
}
355-
}, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously)
359+
else if (t.Exception != null) {
360+
exceptionDispatchInfo = ExceptionDispatchInfo.Capture(t.Exception);
361+
}
362+
}, TaskContinuationOptions.ExecuteSynchronously)
356363
.ConfigureAwait(false);
357364
}
358365
catch (OperationCanceledException) {
359366
await session.DisposeSafelyAsync().ConfigureAwait(false);
360367
throw;
361368
}
369+
finally {
370+
exceptionDispatchInfo?.Throw();
371+
}
362372
}
363373
NotifySessionOpen(session);
364374
return session;

0 commit comments

Comments
 (0)