Skip to content
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

MongoSocketWriteException may be translated into DataAccessResourceFailureException #3568

Closed
boly38 opened this issue Feb 24, 2021 · 1 comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@boly38
Copy link
Contributor

boly38 commented Feb 24, 2021

Hi

What

This is a user feedback about spring data mongodb exception translation:

  • In production we encounter a MongoSocketWriteException during a simple findBy...()
  • spring-data-mongodb translates this exception into a org.springframework.data.mongodb.UncategorizedMongoDbException

Here is an extract of the stack:

org.springframework.data.mongodb.UncategorizedMongoDbException: Exception sending message; nested exception is com.mongodb.MongoSocketWriteException: Exception sending message
	at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:138)
	at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2793)
	at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2698)
	at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:2441)
	at org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.doFind(ExecutableFindOperationSupport.java:214)
	at org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.all(ExecutableFindOperationSupport.java:157)
	at org.springframework.data.mongodb.repository.query.MongoQueryExecution$PagedExecution.execute(MongoQueryExecution.java:121)
	at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:99)
  • on our side we would manage MongoSocketException and other "resource-related" exceptions in the same way but the translator didn't translate MongoSocketWriteException case into DataAccessResourceFailureException so we can't without checking on our side this kind of mongo exceptions..

Version

We're using spring-data-mongodb 3.0.6.RELEASE

but I saw that the relate code dont change.

List of resource-related exception:

private static final Set<String> RESOURCE_FAILURE_EXCEPTIONS = new HashSet<>(
Arrays.asList("MongoException.Network", "MongoSocketException", "MongoException.CursorNotFound",
"MongoCursorNotFoundException", "MongoServerSelectionException", "MongoTimeoutException"));

Why

Today I think the translator translates only an exact match between user-exception and RESOURCE_FAILURE_EXCEPTIONS translation matrix entries.

HowToReproduce

        MongoSocketWriteException writeException = new MongoSocketWriteException("oO", null, null);

        System.out.println(ClassUtils.getShortName(ClassUtils.getUserClass(writeException.getClass())));
        // MongoSocketWriteException

        System.out.println(new MongoExceptionTranslator().translateExceptionIfPossible(writeException));
        // org.springframework.data.mongodb.UncategorizedMongoDbException: oO; nested exception is com.mongodb.MongoSocketWriteException: oO

Fix Suggest

There is no check on user-exception ancestor.

For example, I expect MongoSocketWriteException (child of MongoSocketException) like all other MongoSocketException childs to be translated into DataAccessResourceFailureException.

Am I wrong?
If I'm right, do you plan to improve MongoExceptionTranslator this way ?

Regards

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 24, 2021
@mp911de
Copy link
Member

mp911de commented Feb 25, 2021

UncategorizedMongoDbException isn't ideal. It makes sense to consider a broader translation of MongoSocketException to DataAccessResourceFailureException. Feel free to submit a pull request.

@mp911de mp911de added status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 25, 2021
boly38 added a commit to boly38/spring-data-mongodb that referenced this issue Feb 25, 2021
boly38 added a commit to boly38/spring-data-mongodb that referenced this issue Mar 1, 2021
@mp911de mp911de added this to the 3.0.8 (Neumann SR8) milestone Mar 2, 2021
@mp911de mp911de closed this as completed in 39e301d Mar 2, 2021
mp911de added a commit that referenced this issue Mar 2, 2021
Reformat code. Reduce method visibility in JUnit 5 tests. Add Nullable annotations to address warnings.

See #3568
Original pull request: #3569.
mp911de pushed a commit that referenced this issue Mar 2, 2021
mp911de added a commit that referenced this issue Mar 2, 2021
Reformat code. Reduce method visibility in JUnit 5 tests. Add Nullable annotations to address warnings.

See #3568
Original pull request: #3569.
mp911de pushed a commit that referenced this issue Mar 2, 2021
mp911de added a commit that referenced this issue Mar 2, 2021
Reformat code. Reduce method visibility in JUnit 5 tests. Add Nullable annotations to address warnings.

See #3568
Original pull request: #3569.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
3 participants