Skip to content

Commit edc5cb4

Browse files
committed
Handle synchronously-thrown exceptions consistently.
Both sync and async exceptions should go through TryAsyncContinuation. This ensures that a synchronously-thrown SocketException will transition the MySqlSession to the failed state.
1 parent a37b695 commit edc5cb4

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/MySqlConnector/Serialization/MySqlSession.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,16 @@ private void ShutdownSocket()
447447
private ValueTask<int> TryAsync<TArg>(Func<TArg, IOBehavior, ValueTask<int>> func, TArg arg, IOBehavior ioBehavior, CancellationToken cancellationToken)
448448
{
449449
VerifyConnected();
450-
var task = func(arg, ioBehavior);
450+
ValueTask<int> task;
451+
try
452+
{
453+
task = func(arg, ioBehavior);
454+
}
455+
catch (Exception ex)
456+
{
457+
task = ValueTaskExtensions.FromException<int>(ex);
458+
}
459+
451460
if (task.IsCompletedSuccessfully)
452461
return task;
453462

@@ -468,7 +477,16 @@ private int TryAsyncContinuation(Task<int> task)
468477
private ValueTask<PayloadData> TryAsync(Func<ProtocolErrorBehavior, IOBehavior, ValueTask<ArraySegment<byte>>> func, IOBehavior ioBehavior, CancellationToken cancellationToken)
469478
{
470479
VerifyConnected();
471-
var task = func(ProtocolErrorBehavior.Throw, ioBehavior);
480+
ValueTask<ArraySegment<byte>> task;
481+
try
482+
{
483+
task = func(ProtocolErrorBehavior.Throw, ioBehavior);
484+
}
485+
catch (Exception ex)
486+
{
487+
task = ValueTaskExtensions.FromException<ArraySegment<byte>>(ex);
488+
}
489+
472490
if (task.IsCompletedSuccessfully)
473491
{
474492
var payload = new PayloadData(task.Result);

0 commit comments

Comments
 (0)