[SERVER-53451] All continuations in resharding primary only services run methods should capture this as shared_from_this Created: 18/Dec/20  Updated: 06/Dec/22  Resolved: 22/Dec/20

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Janna Golden Assignee: [DO NOT USE] Backlog - Sharding Team
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Sharding
Operating System: ALL
Participants:

 Description   

When a state document is deleted, any shared_ptr references to 'this' in the primary only service machinery are destroyed. If the future chain in any primary only service's run method has not finished and the state document for that object has been removed, we'll seg fault and crash. Each service captures 'this' as 'shared_from_this' after the point that it expects that its state doc will be removed, but to protect against seg faulting (and crashing) in the event that a user accidentally deletes a doc or drops the collection entirely we should capture 'this' as 'shared_from_this' for each continuation.



 Comments   
Comment by Max Hirschhorn [ 18/Dec/20 ]

Being robust to situations where the state document is removed unexpectedly is a great point.

After discussing a little with Sam, I don't think it is strictly necessary to capture shared_from_this() in earlier parts of the future chain. PrimaryOnlyService::_scheduleRun() guarantees that the PrimaryOnlyService Instance is alive at least until run() returns. By the time ReshardingCoordinator::run() returns, we'll have defined at least one lambda which captures shared_from_this(). This means that the this pointer will remain valid as earlier parts of the future chain start to execute both while ReshardingCoordinator::run() is running and after ReshardingCoordinator::run() has returned.

Generated at Thu Feb 08 05:30:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.