Skip to content

Commit

Permalink
fix(NODE-3688): check handshake error when applying label
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Apr 20, 2022
1 parent 5b28e91 commit adc053c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,16 @@ export function needsRetryableWriteLabel(error: Error, maxWireVersion: number):
return true;
}

if (
maxWireVersion >= 9 ||
(error instanceof MongoError && error.hasErrorLabel(MongoErrorLabel.RetryableWriteError))
) {
// If we already have the error label no need to add it again. 4.4+ servers add the label.
return false;
if (error instanceof MongoError) {
if (
(maxWireVersion >= 9 || error.hasErrorLabel(MongoErrorLabel.RetryableWriteError)) &&
!error.hasErrorLabel(MongoErrorLabel.HandshakeError)
) {
// If we already have the error label no need to add it again. 4.4+ servers add the label.
// In the case where we have a handshake error, need to fall down to the logic checking
// the codes.
return false;
}
}

if (error instanceof MongoWriteConcernError) {
Expand All @@ -781,10 +785,7 @@ export function needsRetryableWriteLabel(error: Error, maxWireVersion: number):
}

export function isRetryableWriteError(error: MongoError): boolean {
return (
error.hasErrorLabel(MongoErrorLabel.RetryableWriteError) ||
error.hasErrorLabel(MongoErrorLabel.HandshakeError)
);
return error.hasErrorLabel(MongoErrorLabel.RetryableWriteError);
}

/** Determines whether an error is something the driver should attempt to retry */
Expand Down

0 comments on commit adc053c

Please sign in to comment.