-
Notifications
You must be signed in to change notification settings - Fork 1.5k
JAVA-5949 preserve connection pool on backpressure errors when establishing connections #1900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: backpressure
Are you sure you want to change the base?
Changes from all commits
21abfe2
339297b
2e44072
4cff1b2
0a93dd7
b1f4ba0
1b1558d
fcdfa23
d423093
bce97d4
41b2773
508d741
c5e68fc
71c91f0
6afa1a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.mongodb.internal.connection; | ||
|
|
||
| import com.mongodb.MongoException; | ||
| import com.mongodb.MongoSecurityException; | ||
| import com.mongodb.MongoSocketException; | ||
|
|
||
| import javax.net.ssl.SSLHandshakeException; | ||
| import javax.net.ssl.SSLPeerUnverifiedException; | ||
| import javax.net.ssl.SSLProtocolException; | ||
| import java.net.UnknownHostException; | ||
| import java.security.cert.CertPathBuilderException; | ||
| import java.security.cert.CertPathValidatorException; | ||
| import java.security.cert.CertificateException; | ||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Attaches {@link MongoException#SYSTEM_OVERLOADED_ERROR_LABEL} and | ||
| * {@link MongoException#RETRYABLE_ERROR_LABEL} to network errors encountered during connection | ||
| * establishment or the hello message, per the CMAP specification. | ||
| * | ||
| * <p>This is topology-agnostic: it must be invoked from the connection-establishment path so that | ||
| * both default SDAM and load-balanced modes are covered. | ||
| */ | ||
| final class BackpressureErrorLabeler { | ||
|
|
||
| private BackpressureErrorLabeler() { | ||
| } | ||
|
|
||
| static void applyLabelsIfEligible(final Throwable t) { | ||
| if (!(t instanceof MongoException)) { | ||
| return; | ||
| } | ||
| if (t instanceof MongoSecurityException) { | ||
| return; | ||
| } | ||
| if (!(t instanceof MongoSocketException)) { | ||
| return; | ||
| } | ||
| if (isDnsLookupFailure(t)) { | ||
| return; | ||
| } | ||
| if (isTlsConfigurationError(t)) { | ||
| return; | ||
| } | ||
| // TODO-BACKPRESSURE Nabil - SOCKS5 Revisit alongside JAVA-5205 (SOCKS5 in async) so both sync and | ||
| // async proxy error surfaces can be handled together — likely via a dedicated internal | ||
| // exception thrown from the proxy code path. | ||
| MongoException mongoException = (MongoException) t; | ||
| mongoException.addLabel(MongoException.SYSTEM_OVERLOADED_ERROR_LABEL); | ||
| mongoException.addLabel(MongoException.RETRYABLE_ERROR_LABEL); | ||
| } | ||
|
|
||
| static boolean isDnsLookupFailure(final Throwable t) { | ||
| Throwable cause = t.getCause(); | ||
| while (cause != null) { | ||
| if (cause instanceof UnknownHostException) { | ||
| return true; | ||
| } | ||
| cause = cause.getCause(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static boolean isTlsConfigurationError(final Throwable t) { | ||
| if (!(t instanceof MongoSocketException)) { | ||
| return false; | ||
| } | ||
| Throwable cause = t.getCause(); | ||
| while (cause != null) { | ||
| if (cause instanceof CertificateException | ||
| || cause instanceof CertPathBuilderException | ||
| || cause instanceof CertPathValidatorException | ||
| || cause instanceof SSLPeerUnverifiedException | ||
| || cause instanceof SSLProtocolException) { | ||
| return true; | ||
| } | ||
| if (cause instanceof SSLHandshakeException) { | ||
| String message = cause.getMessage(); | ||
| if (message != null) { | ||
| String lowerMessage = message.toLowerCase(Locale.ROOT); | ||
| if (lowerMessage.contains("certificate") | ||
| || lowerMessage.contains("verify") | ||
| || lowerMessage.contains("trust") | ||
| || lowerMessage.contains("hostname") | ||
| || lowerMessage.contains("protocol") | ||
| || lowerMessage.contains("cipher") | ||
| || lowerMessage.contains("handshake_failure")) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| cause = cause.getCause(); | ||
| } | ||
| return false; | ||
| } | ||
| } |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [this comment is left on a file, but has nothing to do with the file; this is done so that we could reply to the comment; commenting on a PR does not allow replies - horrendous GitHub functionality]
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Description updated. All specs are implemented
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [this comment is left on a file, but has nothing to do with the file; this is done so that we could reply to the comment; commenting on a PR does not allow replies - horrendous GitHub functionality] JAVA-5949 has an old comment, which instructs to re-enable some tests that were previously disabled when we updated the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR no longer depends on #1856. Spec PR mongodb/specifications#1880 rewrote the |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[this comment is left on a file, but has nothing to do with the file; this is done so that we could reply to the comment; commenting on a PR does not allow replies - horrendous GitHub functionality]
The current PR seemingly depends on #1856 (see the description of the current PR). We need to decide what to do with that.
P.S. I originally left my thoughts in the description of this PR, but I don't know if that's what we are going to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer depend on this PR see #1900 (comment)