|
7 | 7 | using System; |
8 | 8 | using System.Collections.Concurrent; |
9 | 9 | using System.Collections.Generic; |
| 10 | +using System.Runtime.ExceptionServices; |
10 | 11 | using System.Threading; |
11 | 12 | using System.Threading.Tasks; |
12 | 13 | using JetBrains.Annotations; |
@@ -346,19 +347,28 @@ internal async Task<Session> OpenSessionInternalAsync(SessionConfiguration confi |
346 | 347 | // That would make session accessible for user before |
347 | 348 | // connection become opened. |
348 | 349 | session = new Session(this, storageNode, configuration, false); |
| 350 | + ExceptionDispatchInfo exceptionDispatchInfo = null; |
349 | 351 | try { |
350 | 352 | await ((SqlSessionHandler) session.Handler).OpenConnectionAsync(cancellationToken) |
351 | 353 | .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 | + } |
354 | 358 | } |
355 | | - }, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously) |
| 359 | + else if (t.Exception != null) { |
| 360 | + exceptionDispatchInfo = ExceptionDispatchInfo.Capture(t.Exception); |
| 361 | + } |
| 362 | + }, TaskContinuationOptions.ExecuteSynchronously) |
356 | 363 | .ConfigureAwait(false); |
357 | 364 | } |
358 | 365 | catch (OperationCanceledException) { |
359 | 366 | await session.DisposeSafelyAsync().ConfigureAwait(false); |
360 | 367 | throw; |
361 | 368 | } |
| 369 | + finally { |
| 370 | + exceptionDispatchInfo?.Throw(); |
| 371 | + } |
362 | 372 | } |
363 | 373 | NotifySessionOpen(session); |
364 | 374 | return session; |
|
0 commit comments