File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -1528,13 +1528,7 @@ export function isNodeShuttingDownError(err: MongoError): boolean {
15281528 *
15291529 * @see https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md#not-writable-primary-and-node-is-recovering
15301530 */
1531- export function isSDAMUnrecoverableError ( error : MongoError ) : boolean {
1532- // NOTE: null check is here for a strictly pre-CMAP world, a timeout or
1533- // close event are considered unrecoverable
1534- if ( error instanceof MongoParseError || error == null ) {
1535- return true ;
1536- }
1537-
1531+ export function isStateChangeError ( error : MongoError ) : boolean {
15381532 return isRecoveringError ( error ) || isNotWritablePrimaryError ( error ) ;
15391533}
15401534
Original file line number Diff line number Diff line change @@ -22,12 +22,13 @@ import {
2222import {
2323 type AnyError ,
2424 isNodeShuttingDownError ,
25- isSDAMUnrecoverableError ,
25+ isStateChangeError ,
2626 MONGODB_ERROR_CODES ,
2727 MongoError ,
2828 MongoErrorLabel ,
2929 MongoNetworkError ,
3030 MongoNetworkTimeoutError ,
31+ MongoParseError ,
3132 MongoRuntimeError ,
3233 MongoServerClosedError ,
3334 type MongoServerError ,
@@ -412,7 +413,14 @@ export class Server extends TypedEventEmitter<ServerEvents> {
412413 this . pool . clear ( { serviceId : connection . serviceId } ) ;
413414 }
414415 } else {
415- if ( isSDAMUnrecoverableError ( error ) ) {
416+ // TODO: considering parse errors as SDAM unrecoverable errors seem
417+ // questionable. What if the parse error only comes from an application connection,
418+ // indicating some bytes were lost in transmission? It seems overkill to completely
419+ // kill the server.
420+ // Parse errors from monitoring connections are already handled because the
421+ // error would be wrapped in a ServerHeartbeatFailedEvent, which would mark the
422+ // server unknown and clear the pool. Can we remove this?
423+ if ( isStateChangeError ( error ) || error instanceof MongoParseError ) {
416424 if ( shouldHandleStateChangeError ( this , error ) ) {
417425 const shouldClearPool = isNodeShuttingDownError ( error ) ;
418426 if ( this . loadBalanced && connection && shouldClearPool ) {
You can’t perform that action at this time.
0 commit comments