Skip to content

Commit 32cd321

Browse files
committed
Added an explicit API for ShouldCallConnectionFailed to make it look like the other methods, even though it is not really needed.
1 parent 33ed459 commit 32cd321

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/MongoDB.Driver/Core/Connections/BinaryConnection.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ private void ConnectionFailed(Exception exception)
155155
{
156156
_failedEventHasBeenRaised = true;
157157
_eventLogger.LogAndPublish(new ConnectionFailedEvent(_connectionId, exception));
158-
_commandEventHelper.ConnectionFailed(_connectionId, _description?.ServiceId, exception, IsInitializing);
158+
159+
if (_commandEventHelper.ShouldCallConnectionFailed)
160+
{
161+
_commandEventHelper.ConnectionFailed(_connectionId, _description?.ServiceId, exception, IsInitializing);
162+
}
159163
}
160164
}
161165

src/MongoDB.Driver/Core/Connections/CommandEventHelper.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public CommandEventHelper(EventLogger<LogCategories.Command> eventLogger, Tracin
7878

7979
public bool ShouldCallErrorReceiving => _eventsNeedState || ShouldTraceWithActivityListener();
8080

81+
public bool ShouldCallConnectionFailed => (_shouldTrackFailed || ShouldTraceWithActivityListener()) && _state != null;
82+
8183
private bool ShouldTraceWithActivityListener()
8284
=> !_tracingDisabled && MongoTelemetry.ActivitySource.HasListeners();
8385

@@ -227,16 +229,6 @@ public void ErrorReceiving(int responseTo, ConnectionId connectionId, ObjectId?
227229

228230
public void ConnectionFailed(ConnectionId connectionId, ObjectId? serviceId, Exception exception, bool skipLogging)
229231
{
230-
if (!_shouldTrackFailed && !ShouldTraceWithActivityListener())
231-
{
232-
return;
233-
}
234-
235-
if (_state == null)
236-
{
237-
return;
238-
}
239-
240232
CompleteFailedCommandActivity(exception);
241233

242234
var requestIds = _state.Keys;

0 commit comments

Comments
 (0)