Skip to content

Commit 99b520e

Browse files
authored
fix: Retry connection on HttpRequestException error (#1514) (#1484)
1 parent 925d016 commit 99b520e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionManager.cs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.IO;
1111
using System.Linq;
1212
using System.Net;
13+
using System.Net.Http;
1314
using System.Net.Sockets;
1415

1516
namespace NewRelic.Agent.Core.DataTransport
@@ -106,6 +107,12 @@ private void Connect()
106107
{
107108
HandleHttpErrorResponse(ex);
108109
}
110+
// Occurs when the agent is unable to connect to APM. The request failed due to an underlying
111+
// issue such as network connectivity, DNS failure, server certificate validation or timeout.
112+
catch (HttpRequestException)
113+
{
114+
ScheduleRestart();
115+
}
109116
// Occurs when the agent connects to APM but the connection gets aborted by the collector
110117
catch (SocketException)
111118
{

tests/Agent/UnitTests/Core.UnitTest/DataTransport/ConnectionManagerTests.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
using System;
55
using System.IO;
66
using System.Net;
7+
using System.Net.Http;
78
using System.Net.Sockets;
9+
using System.Web;
810
using NewRelic.Agent.Configuration;
911
using NewRelic.Agent.Core.Events;
10-
using NewRelic.Agent.Core.Exceptions;
1112
using NewRelic.Agent.Core.Fixtures;
1213
using NewRelic.Agent.Core.Time;
1314
using NewRelic.Agent.Core.Utilities;
1415
using NUnit.Framework;
1516
using Telerik.JustMock;
17+
using HttpException = NewRelic.Agent.Core.Exceptions.HttpException;
1618

1719
namespace NewRelic.Agent.Core.DataTransport
1820
{
@@ -83,6 +85,7 @@ public void AttemptAutoStart_SchedulesConnectAsynchronously_IfAutoStartIsOnAndSy
8385
[Test]
8486
[TestCase("ForceRestartException")]
8587
[TestCase("HttpException")]
88+
[TestCase("HttpRequestException")]
8689
[TestCase("SocketException")]
8790
[TestCase("IOException")]
8891
[TestCase("OperationCanceledException")]
@@ -97,6 +100,9 @@ public void AttemptAutoStart_SchedulesReconnect_IfCertainExceptionOccurs(string
97100
case "HttpException":
98101
ex = new HttpException(HttpStatusCode.MethodNotAllowed, null);
99102
break;
103+
case "HttpRequestException":
104+
ex = new HttpRequestException();
105+
break;
100106
case "SocketException":
101107
ex = new SocketException();
102108
break;

0 commit comments

Comments
 (0)