[SERVER-34571] Invariant fails in destructor of MigrationChunkClonerSourceLegacy on shutdown Created: 19/Apr/18  Updated: 29/Oct/23  Resolved: 23/Apr/18

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 3.4.15, 3.6.5, 3.7.6

Type: Bug Priority: Major - P3
Reporter: Matthew Saltz (Inactive) Assignee: Matthew Saltz (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.6, v3.4
Sprint: Sharding 2018-05-07
Participants:
Linked BF Score: 1

 Description   

When we try to cleanup the MigrationSourceManager on error (cleanupOnError), we also clean up the MigrationChunkClonerSourceLegacy object (call cancelClone, which calls _cleanup), and then the MigrationChunkClonerSourceLegacy object is destructed. In the destructor, there's an invariant

invariant(!_deleteNotifyExec);

_deleteNotifyExec is a unique_ptr to a PlanExecutor object. In theory, in _cleanup(), it should be reset and destructed - hence the invariant. However, if an exception is thrown in _cleanup before this happens, and then ~MigrationChunkClonerSourceLegacy gets called, the program will abort since we're throwing an exception while already throwing an exception, which is A Bad Thing™. In the case of BF-8673 this seems to be what happened, presumably due to one of the functions in _cleanup failing due to shutdown being in progress. We could potentially fix this by wrapping these functions in a try-catch, or instead of using _deleteNotifyExec.reset() we could just std::move(_deleteNotifyExec) into the local scope so that _deleteNotifyExec will indeed be empty no matter what, and this invariant won't fail.



 Comments   
Comment by Githook User [ 23/Apr/18 ]

Author:

{'email': 'matthew.saltz@mongodb.com', 'name': 'Matthew Saltz'}

Message: SERVER-34571 Ensure _deleteNotifyExec in MigrationChunkClonerSourceLegacy always reset on cleanup

(cherry picked from commit 179985c786cea234b65946ff647debfdfdbed511)
Branch: v3.6
https://github.com/mongodb/mongo/commit/2dff7f1f50540af8aa1b982b41b4dd752068c89e

Comment by Githook User [ 23/Apr/18 ]

Author:

{'email': 'matthew.saltz@mongodb.com', 'name': 'Matthew Saltz'}

Message: SERVER-34571 Ensure _deleteNotifyExec in MigrationChunkClonerSourceLegacy always reset on cleanup

(cherry picked from commit 179985c786cea234b65946ff647debfdfdbed511)
Branch: v3.4
https://github.com/mongodb/mongo/commit/4af95dc93dbe306778e94f1d487f4e9afa57c8a9

Comment by Githook User [ 23/Apr/18 ]

Author:

{'email': 'matthew.saltz@mongodb.com', 'name': 'Matthew Saltz'}

Message: SERVER-34571 Ensure _deleteNotifyExec in MigrationChunkClonerSourceLegacy always reset on cleanup
Branch: master
https://github.com/mongodb/mongo/commit/179985c786cea234b65946ff647debfdfdbed511

Comment by Matthew Saltz (Inactive) [ 20/Apr/18 ]

CR: https://mongodbcr.appspot.com/197680001/

Generated at Thu Feb 08 04:37:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.