@@ -51,6 +51,7 @@ import org.bson.BsonInt32
5151import org.bson.codecs.BsonDocumentCodec
5252import spock.lang.Specification
5353
54+ import java.security.cert.CertificateException
5455import java.util.concurrent.CountDownLatch
5556
5657import static com.mongodb.ClusterFixture.CLIENT_METADATA
@@ -258,12 +259,9 @@ class DefaultServerSpecification extends Specification {
258259 ]
259260 }
260261
261- def ' DNS lookup failure should not be labeled as backpressure and should invalidate the pool ' () {
262+ def ' should invalidate the pool when the exception without system overloaded label ' () {
262263 given :
263- def exceptionToThrow = new MongoSocketException (' DNS lookup failed' , new ServerAddress (),
264- new UnknownHostException (' no such host' ))
265- BackpressureErrorLabeler . applyLabelsIfEligible(exceptionToThrow)
266-
264+ assert ! exceptionToThrow. hasErrorLabel(MongoException . SYSTEM_OVERLOADED_ERROR_LABEL )
267265 def connectionPool = Mock (ConnectionPool )
268266 connectionPool. get(_) >> { throw exceptionToThrow }
269267 def serverMonitor = Mock (ServerMonitor )
@@ -275,9 +273,40 @@ class DefaultServerSpecification extends Specification {
275273 then :
276274 def e = thrown(MongoException )
277275 e. is(exceptionToThrow)
278- ! e. hasErrorLabel(MongoException . SYSTEM_OVERLOADED_ERROR_LABEL )
279276 1 * connectionPool. invalidate(exceptionToThrow)
280277 1 * serverMonitor. cancelCurrentCheck()
278+
279+ where :
280+ exceptionToThrow << [
281+ new MongoSocketException (' establishment failed' , new ServerAddress ()),
282+ new MongoSocketOpenException (' open failed' , new ServerAddress (), new IOException ()),
283+ new MongoSocketReadTimeoutException (' Read timed out' , new ServerAddress (), new IOException ()),
284+ new MongoSocketException (' DNS lookup failed' , new ServerAddress (),
285+ new UnknownHostException (' no such host' )),
286+ new MongoSocketException (' TLS config error' , new ServerAddress (),
287+ new CertificateException (' bad cert' )),
288+ ]
289+ }
290+
291+ def ' should not invalidate the pool when the exception carries SystemOverloadedError' () {
292+ given :
293+ def exceptionToThrow = new MongoSocketException (' rate-limited establishment' , new ServerAddress ())
294+ exceptionToThrow. addLabel(MongoException . SYSTEM_OVERLOADED_ERROR_LABEL )
295+
296+ def connectionPool = Mock (ConnectionPool )
297+ connectionPool. get(_) >> { throw exceptionToThrow }
298+ def serverMonitor = Mock (ServerMonitor )
299+ def server = defaultServer(connectionPool, serverMonitor)
300+
301+ when :
302+ server. getConnection(createOperationContext())
303+
304+ then :
305+ def e = thrown(MongoException )
306+ e. is(exceptionToThrow)
307+ e. hasErrorLabel(MongoException . SYSTEM_OVERLOADED_ERROR_LABEL )
308+ 0 * connectionPool. invalidate(_)
309+ 0 * serverMonitor. cancelCurrentCheck()
281310 }
282311
283312 def ' failed authentication should invalidate the connection pool' () {
0 commit comments