[SERVER-66456] remove ThreadContext Created: 13/May/22  Updated: 29/Oct/23  Resolved: 16/May/22

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

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

Issue Links:
Depends
depends on SERVER-66385 Remove ThreadName's dependence on Thr... Closed
Issue split
split to SERVER-66466 Remove TransportLayerASIOTest depende... Closed
Related
related to SERVER-54900 Blocking networking calls can delay s... Closed
related to SERVER-58194 Fix undefined behavior in the destruc... Closed
related to SERVER-63852 getThreadName() should not crash Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Service Arch 2022-05-30
Participants:
Linked BF Score: 135

 Description   

Work on SERVER-66385 revealed that ThreadContext doesn't and likely cannot live up to the promise in its documentation of being in a 1-to-1 (bijective) relationship with threads. It can only come into existence when a thread calls ThreadContext::get after MONGO_INITIALIZERs and before static duration object destruction. These contraints are a source of several recent bugs.

As a Decorable, it can only be created after MONGO_INITIALIZERs, which makes it harder to reason about, and it cannot be used during program shutdown (SERVER-58194 is a bug caused by this). As a thread_local, it must be destroyed before static objects so it is unavailable at shutdown time, even for the main thread. After SERVER-66385, we don't actually need a ThreadContext at all.

The only remaining use of ThreadContext is a recent test (according to comments in the test it is nondeterministic anyway (https://github.com/mongodb/mongo/commit/263c0631c8001a8cdb42aff720b8a49a621754dd#diff-db39491b47a2be852cb29c36e80fd1932a990c129bd17586578bfed398626b38) , and what it's doing can be better done with `FailPoint` or other test injection techniques, as there's a specific thread spawn call that it's looking for.



 Comments   
Comment by Githook User [ 16/May/22 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-66456 remove ThreadContext
Branch: master
https://github.com/mongodb/mongo/commit/b01267d79d7540cd7ad2198776b2eca17eeb396c

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