Skip to content

Commit

Permalink
Fix SmtpClient.Dispose() when telemetry is configured
Browse files Browse the repository at this point in the history
Also discovered some issues in CreateMetrics() methods in Telemetry class.

Fixes issue #1816
  • Loading branch information
jstedfast committed Sep 18, 2024
1 parent 00a6dc2 commit 0fb7ad9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion MailKit/Net/Smtp/SmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,9 @@ public override void NoOp (CancellationToken cancellationToken = default)

void Disconnect (string host, int port, SecureSocketOptions options, bool requested)
{
RecordClientDisconnected (null);
// Note: if the uri is null, then the user manually disconnected already.
if (uri != null)
RecordClientDisconnected (null);

capabilities = SmtpCapabilities.None;
authenticated = false;
Expand Down
6 changes: 3 additions & 3 deletions MailKit/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static class SmtpClient

internal static ClientMetrics CreateMetrics (Meter meter)
{
return new ClientMetrics (Meter, MeterName, "an", "SMTP");
return new ClientMetrics (meter, MeterName, "an", "SMTP");
}

/// <summary>
Expand Down Expand Up @@ -236,7 +236,7 @@ public static class Pop3Client

internal static ClientMetrics CreateMetrics (Meter meter)
{
return new ClientMetrics (Meter, MeterName, "a", "POP3");
return new ClientMetrics (meter, MeterName, "a", "POP3");
}

/// <summary>
Expand Down Expand Up @@ -321,7 +321,7 @@ public static class ImapClient

internal static ClientMetrics CreateMetrics (Meter meter)
{
return new ClientMetrics (Meter, MeterName, "an", "IMAP");
return new ClientMetrics (meter, MeterName, "an", "IMAP");
}

/// <summary>
Expand Down

0 comments on commit 0fb7ad9

Please sign in to comment.