Skip to content

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale self-assigned this Mar 5, 2022
@stIncMale stIncMale requested a review from jyemin March 5, 2022 19:44
@@ -542,7 +546,8 @@ static boolean shouldAttemptToRetryWrite(final RetryState retryState, final Thro
Throwable failure = attemptFailure instanceof ResourceSupplierInternalException ? attemptFailure.getCause() : attemptFailure;
boolean decision = false;
MongoException exceptionRetryableRegardlessOfCommand = null;
if (failure instanceof MongoConnectionPoolClearedException) {
if (failure instanceof MongoConnectionPoolClearedException
|| (failure instanceof MongoSecurityException && failure.getCause() != null && isRetryableException(failure.getCause()))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test scenario, is the cause of the MongoSecurityException some sort of socket exception? If so, I have a feeling we are mis-categorizing a socket exception as a MongoSecurityException. I don't think that was the intention. In DefaultAuthenticator#wrapException, for example, only a user-non-found code is wrapped (which seems too restrictive, frankly). But in SaslAuthenticator#wrapException, essentially all exceptions are wrapped.

I see three possibilities:

  1. Leave the MongoSecurityException code as is, and leave this check as is
  2. Re-consider MongoSecurityException creation as part of this PR, and simplify this check
  3. Re-consider MongoSecurityException creation as part of a new Jira issue, and simplify this check as part of that work.

I prefer 2 or 3. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test scenario, is the cause of the MongoSecurityException some sort of socket exception?

Not necessary a socket exception, but socket exceptions are also among causes. Examples of the causes in tests are "com.mongodb.MongoSocketReadException: Prematurely reached end of stream", "com.mongodb.MongoNodeIsRecoveringException: Command failed with error 91 (ShutdownInProgress)".

we are mis-categorizing a socket exception as a MongoSecurityException. I don't think that was the intention

Currently the driver wraps everything related to the authentication activity in MongoSecurityException:

  • Exception, ending the list at this point is enough :)
  • MongoCommandException, which may be unrelated to security
  • SaslException, which is an IOException
  • UnknownHostException, which is an IOException
  • GSSException (checked)
  • LoginException (checked)

It is not clear to me whether MongoSecurityException was intended to be used as a wrapper for anything, including IO, that goes wrong during the authentication process. The exception is documented as "thrown when there is an error reported by the underlying client authentication mechanism". If we change what exceptions are wrapped with MongoSecurityException, we will not only have to come up with an approach of discriminating the aforementioned exceptions as security-related and not, but also need to decide what unchecked exception should be used to wrap checked exceptions mentioned above.

Given the above, I think that options 1 and 3 are the only viable ones. And since you'd like us to refactor exception handling related to authentication, I will create a ticket for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stIncMale stIncMale merged commit 70ad9c9 into mongodb:master Mar 7, 2022
@stIncMale stIncMale deleted the JAVA-4354 branch March 7, 2022 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants