This repository has been archived by the owner on May 28, 2018. It is now read-only.
#3293 Pre-load default ssl socket factory in HttpUrlConnector #3738
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@mpotociar @petrbouda this PR is a potential fix for #3293
From my understanding of the current code, the logic for using a custom SSL socket factory is:
HttpsUrlConnection
returned by theConnectionFactory
already has a customSSLSocketFactory
set on it, do nothingSSLContext
in the client config.Currently, the first check is done via:
The issue with this code is that
HttpsURLConnection.getDefaultSSLSocketFactory()
is not thread safe. The implementation looks like:If there are concurrent requests, one of them may end up creating a separate
SSLSocketFactory
that is not the default. The comparison check above fails and the request ends up using the default SSL context instead of the provided one.The fix in this PR is to call
HttpsURLConnection.getDefaultSSLSocketFactory()
in a static initializer block for the class so that the default SSLContext is present when the comparison is made inHttpUrlConnector#secureConnector
I'm open to feedback on alternate approaches to resolving this.