Skip to content

Commit 0d533e0

Browse files
committed
Only call SetSuccess if successful.
Remove an unnecessary guard in SetSuccess; the method assumes it will only be called appropriately.
1 parent c9dfdd7 commit 0d533e0

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/MySqlConnector/MySqlDataReader.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ internal static async Task<MySqlDataReader> CreateAsync(CommandListPosition comm
481481
activity.SetException(ex);
482482
activity.Stop();
483483
}
484+
dataReader.m_creationFailed = true;
484485
dataReader.Dispose();
485486
throw;
486487
}
@@ -622,7 +623,8 @@ internal async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancel
622623
Command.CancellableCommand.SetTimeout(Constants.InfiniteTimeout);
623624
connection.FinishQuerying(m_hasWarnings);
624625

625-
Activity?.SetSuccess();
626+
if (!m_creationFailed)
627+
Activity?.SetSuccess();
626628
Activity?.Stop();
627629

628630
if ((m_behavior & CommandBehavior.CloseConnection) != 0)
@@ -682,7 +684,8 @@ private ResultSet GetResultSet()
682684
private CommandListPosition m_commandListPosition;
683685
private bool m_closed;
684686
private bool m_hasWarnings;
685-
private ResultSet? m_resultSet;
686687
private bool m_hasMoreResults;
688+
private bool m_creationFailed;
689+
private ResultSet? m_resultSet;
687690
private DataTable? m_schemaTable;
688691
}

src/MySqlConnector/Utilities/ActivitySourceHelper.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@ internal static class ActivitySourceHelper
4141
public static void SetSuccess(this Activity activity)
4242
{
4343
#if NET6_0_OR_GREATER
44-
if (activity.Status == ActivityStatusCode.Unset)
45-
{
46-
activity.SetStatus(ActivityStatusCode.Ok);
47-
}
44+
activity.SetStatus(ActivityStatusCode.Ok);
4845
#else
49-
if (activity.Duration == TimeSpan.Zero)
50-
{
51-
activity.SetTag(StatusCodeTagName, "OK");
52-
}
46+
activity.SetTag(StatusCodeTagName, "OK");
5347
#endif
5448
}
5549

0 commit comments

Comments
 (0)