[SERVER-71106] Access to Grid members should be protected with isShardingInitialized Created: 04/Nov/22  Updated: 29/Oct/23  Resolved: 23/May/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Randolph Tan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-32677 Segmentation fault converting Replica... Closed
is related to SERVER-73960 Support setFCV transitions when catal... Closed
Assigned Teams:
Sharding NYC
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Sharding NYC 2023-03-20, Sharding NYC 2023-04-03, Sharding NYC 2023-04-17, Sharding NYC 2023-05-01
Participants:
Linked BF Score: 0
Story Points: 2

 Description   

Access to Grid members should be protected with isShardingInitialized when it can be called in both sharded and non-sharded context. This is because there is race that happens when addShard is performed, the mongod transitions from being non-sharded to sharded and calls Grid::init, which races with all other places where Grid can be accessed even in non-sharded context.

Some examples include:

https://github.com/mongodb/mongo/blob/cb138e05cf54d14fa886995c329c8da2c235d74b/src/mongo/db/exec/update_stage.cpp#L758
https://github.com/mongodb/mongo/blob/cb138e05cf54d14fa886995c329c8da2c235d74b/src/mongo/db/catalog/coll_mod.cpp#L371



 Comments   
Comment by Githook User [ 23/May/23 ]

Author:

{'name': 'Randolph Tan', 'email': 'randolph@10gen.com', 'username': 'renctan'}

Message: SERVER-71106 Add safety checks for access to Grid members in cases where it can potentially be doing it uninitialized
Branch: master
https://github.com/mongodb/mongo/commit/b8020a6eab3e731f07cee2b37da904aed0608990

Comment by Randolph Tan [ 31/Mar/23 ]

Removing from the PM-2290 epic as I confused ShardingState enabled with Grid::init.

Comment by Randolph Tan [ 04/Nov/22 ]

Note that this is not the first time we encountered this in the code base (SERVER-32677), perhaps we should have the getters always check for isInitialized or if there are any case when it is on a critical path, we can have a special getter the skips the check for cases were it can only be called in a sharded context.

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