[SERVER-5738] Race condition in ONCE/MONGO_ONCE macros Created: 01/May/12 Updated: 05/Apr/17 Resolved: 04/Jan/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Code |
| Affects Version/s: | 2.1.1 |
| Fix Version/s: | 3.5.2 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Andy Schwerin | Assignee: | Mark Benvenuto |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Operating System: | ALL |
| Sprint: | Platforms 2017-01-23 |
| Participants: |
| Description |
|
The definition of MONGO_ONCE contains a race condition. It's current implementation is as follows:
Plain-and-simple not thread safe. |
| Comments |
| Comment by Githook User [ 04/Jan/17 ] |
|
Author: {u'username': u'markbenvenuto', u'name': u'Mark Benvenuto', u'email': u'mark.benvenuto@mongodb.com'}Message: |
| Comment by Andrew Morrow (Inactive) [ 22/Dec/16 ] |
|
I'm in favor of std::call_once. |
| Comment by Mark Benvenuto [ 21/Dec/16 ] |
|
There are two ways to fix this
I prefer we just remove and use std::call_once instead. There are two uses to prevent log spam (authz_session_external_state_server_common.cpp, and btree_logic.cpp), and there is one case in breakpoint(). Other then a test case, it is only used in three places. |
| Comment by Mark Benvenuto [ 19/Dec/16 ] |
|
A better replacement for this in C++11 is std::call_once. http://en.cppreference.com/w/cpp/thread/call_once. |