Skip to content

Commit

Permalink
Removed unnecessary TaskCanceledException handling, add clarifying co…
Browse files Browse the repository at this point in the history
…mments
  • Loading branch information
tippmar-nr committed Dec 18, 2024
1 parent 5648aac commit b890de5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ private void HandleConnectionException(Exception ex)
// Occurs when the agent is unable to connect to APM. The request failed due to an underlying
// issue such as network connectivity, DNS failure, server certificate validation or timeout.
case HttpRequestException:
// Occurs when HttpClient.SendAsync() times out on .NET 6+
case TaskCanceledException:
#endif
// Occurs when the agent connects to APM but the connection gets aborted by the collector
case SocketException:
Expand All @@ -128,6 +126,7 @@ private void HandleConnectionException(Exception ex)
// Occurs when no network connection is available, DNS unavailable, etc.
case WebException:
// Usually occurs when a request times out but did not get far enough along to trigger a timeout exception
// OperationCanceledException is a base class for TaskCanceledException, which can be thrown by HttpClient.SendAsync in .NET 6+
case OperationCanceledException:
Log.Info("Connection failed: {0}", ex.Message);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using NewRelic.Agent.Core.Aggregators;
using NewRelic.Agent.Core.Commands;
using NewRelic.Agent.Core.Events;
using NewRelic.Agent.Core.DataTransport;
using NewRelic.Agent.Core.Segments;
using NewRelic.Agent.Core.ThreadProfiling;
using NewRelic.Agent.Core.Utilities;
Expand All @@ -17,9 +16,6 @@
using System.Linq;
using System.Net;
using System.Net.Sockets;
#if !NETFRAMEWORK
using System.Threading.Tasks;
#endif
namespace NewRelic.Agent.Core.DataTransport
{
public interface IDataTransportService
Expand Down Expand Up @@ -178,18 +174,12 @@ private DataTransportResponse<T> TrySendDataRequest<T>(string method, params obj
var errorStatus = GetDataTransportResponseStatusByHttpStatusCode(ex.StatusCode);
return new DataTransportResponse<T>(errorStatus);
}
catch (Exception ex) when (ex is SocketException or WebException or OperationCanceledException)
// OperationCanceledException is a base class for TaskCanceledException, which can be thrown by HttpClient.SendAsync in .NET 6+
catch (Exception ex) when (ex is SocketException or WebException or OperationCanceledException)
{
LogErrorResponse(ex, method, startTime, null);
return new DataTransportResponse<T>(DataTransportResponseStatus.Retain);
}
#if !NETFRAMEWORK
catch (Exception ex) when (ex is TaskCanceledException) // This exception is specific to .NET 6+
{
LogErrorResponse(ex, method, startTime, null);
return new DataTransportResponse<T>(DataTransportResponseStatus.Retain);
}
#endif
catch (Exception ex)
{
LogErrorResponse(ex, method, startTime, null);
Expand Down

0 comments on commit b890de5

Please sign in to comment.