Skip to content

Commit f3fc596

Browse files
rozzajyemin
authored andcommitted
Fix NPE with unacknowledged retryable bulk writes
JAVA-2922
1 parent 74cede6 commit f3fc596

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

driver-core/src/main/com/mongodb/internal/connection/ProtocolHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ static RequestMessage.EncodingMetadata encodeMessageWithMetadata(final RequestMe
234234
private static final List<Integer> RECOVERING_CODES = asList(11600, 11602, 13436, 189, 91);
235235
public static MongoException createSpecialException(final BsonDocument response, final ServerAddress serverAddress,
236236
final String errorMessageFieldName) {
237+
if (response == null) {
238+
return null;
239+
}
237240
int errorCode = getErrorCode(response);
238241
String errorMessage = getErrorMessage(response, errorMessageFieldName);
239242
if (ErrorCategory.fromErrorCode(errorCode) == ErrorCategory.EXECUTION_TIMEOUT) {

driver-core/src/test/functional/com/mongodb/operation/MixedBulkWriteOperationSpecification.groovy

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,31 @@ class MixedBulkWriteOperationSpecification extends OperationFunctionalSpecificat
10251025
].combinations()
10261026
}
10271027

1028+
@IgnoreIf({ !serverVersionAtLeast(3, 6) || !isDiscoverableReplicaSet() })
1029+
def 'should not fail with unacknowledged writes, retryWrites and failPoints'() {
1030+
given:
1031+
def testWrites = getTestWrites()
1032+
getCollectionHelper().insertDocuments(getTestInserts())
1033+
def operation = new MixedBulkWriteOperation(getNamespace(), testWrites, true, UNACKNOWLEDGED, true)
1034+
1035+
when:
1036+
enableOnPrimaryTransactionalWriteFailPoint(BsonDocument.parse(failPoint))
1037+
def result = executeWithSession(operation, async)
1038+
1039+
then:
1040+
result == BulkWriteResult.unacknowledged()
1041+
1042+
cleanup:
1043+
disableOnPrimaryTransactionalWriteFailPoint()
1044+
1045+
where:
1046+
[async, failPoint] << [
1047+
[true, false],
1048+
['{mode: {times: 2}, data: {failBeforeCommitExceptionCode : 1}}',
1049+
'{mode: {skip: 2}, data: {failBeforeCommitExceptionCode : 1}}']
1050+
].combinations()
1051+
}
1052+
10281053
@IgnoreIf({ !serverVersionAtLeast(3, 6) })
10291054
def 'should retry if the connection initially fails'() {
10301055
when:

0 commit comments

Comments
 (0)