Skip to content

Commit e3e15d0

Browse files
nhachicharozza
andcommitted
Update driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java
Co-authored-by: Ross Lawley <[email protected]>
1 parent f099711 commit e3e15d0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,34 @@ public void run() {
227227
// to fire the ServerHeartbeatSucceededEvent
228228
continue;
229229
}
230+
boolean isPollMode = serverSettings.getServerMonitoringMode().equals(ServerMonitoringMode.POLL);
231+
ServerDescription unknownConnectingServerDescription = unknownConnectingServerDescription(serverId, null);
232+
ServerDescription currentServerDescription = unknownConnectingServerDescription;
233+
try {
234+
while (!isClosed) {
235+
ServerDescription previousServerDescription = currentServerDescription;
236+
currentServerDescription = lookupServerDescription(currentServerDescription);
237+
boolean shouldStreamResponses = shouldStreamResponses(currentServerDescription);
238+
if (shouldStreamResponses) {
239+
ensureRoundTripTimeMonitorStarted();
240+
}
241+
242+
if (isClosed) {
243+
continue;
244+
}
245+
246+
if (currentCheckCancelled) {
247+
waitForNext();
248+
currentCheckCancelled = false;
249+
continue;
250+
}
251+
252+
// For POLL mode, if we just established initial connection, do an immediate heartbeat
253+
if (isPollMode && connection != null && !connection.isClosed()
254+
&& previousServerDescription.equals(unknownConnectingServerDescription)
255+
&& currentServerDescription.equals(connection.getInitialServerDescription())) {
256+
continue;
257+
}
230258

231259
logStateChange(previousServerDescription, currentServerDescription);
232260
sdamProvider.get().monitorUpdate(currentServerDescription);

0 commit comments

Comments
 (0)