Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
import com.mongodb.connection.ServerType;
import com.mongodb.event.ServerDescriptionChangedEvent;
import com.mongodb.event.ServerListener;
import com.mongodb.internal.diagnostics.logging.Logger;
import com.mongodb.internal.diagnostics.logging.Loggers;

import static com.mongodb.assertions.Assertions.assertFalse;
import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.assertions.Assertions.assertTrue;
import static com.mongodb.connection.ServerType.UNKNOWN;
import static com.mongodb.internal.connection.EventHelper.wouldDescriptionsGenerateEquivalentEvents;
import static com.mongodb.internal.connection.ServerDescriptionHelper.unknownConnectingServerDescription;
import static java.lang.String.format;

@ThreadSafe
final class DefaultSdamServerDescriptionManager implements SdamServerDescriptionManager {
private static final Logger LOGGER = Loggers.getLogger("connection");
private final Cluster cluster;
private final ServerId serverId;
private final ServerListener serverListener;
Expand Down Expand Up @@ -135,6 +139,15 @@ private void handleException(final SdamIssue sdamIssue, final boolean beforeHand
connectionPool.invalidate(sdamIssue.exception().orElse(null));
}
serverMonitor.connect();
} else if (beforeHandshake
&& (sdamIssue.relatedToNetworkNotTimeout() || sdamIssue.relatedToNetworkTimeout())) {
// clients MUST NOT clear the connection pool and MUST NOT mark the server Unknown when a connection establishment
// fails with network errors or timeouts
// TODO if we can detect reliably TLS handshake error (ex revoked certificate) we may choose to clear the pool and mark the
// server unknown
LOGGER.info(format("Connection pool is not cleared and server is not marked Unknown since we encountered a timeout or network"
+ " error before the handshake: %s", sdamIssue.exception().orElse(null)));
serverMonitor.cancelCurrentCheck();
} else if (sdamIssue.relatedToNetworkNotTimeout()
|| (beforeHandshake && (sdamIssue.relatedToNetworkTimeout() || sdamIssue.relatedToAuth()))) {
updateDescription(sdamIssue.serverDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class DefaultServerSpecification extends Specification {
]
}

def 'failed open should invalidate the server'() {
def 'timeout and network error should not invalidate the pool'() {
given:
def connectionPool = Mock(ConnectionPool)
connectionPool.get(_) >> { throw exceptionToThrow }
Expand All @@ -247,7 +247,7 @@ class DefaultServerSpecification extends Specification {
then:
def e = thrown(MongoException)
e.is(exceptionToThrow)
1 * connectionPool.invalidate(exceptionToThrow)
0 * connectionPool.invalidate(exceptionToThrow)
1 * serverMonitor.cancelCurrentCheck()

where:
Expand Down