[SERVER-28958] Windows --dbg=on --opt=off build of mongod does not start Created: 25/Apr/17  Updated: 30/Oct/23  Resolved: 26/Apr/17

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 3.5.7
Fix Version/s: 3.5.7

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

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Build Windows Enterprise using this command line (the library paths are relative to my development machine):

buildscripts\scons.py -j 12 --dbg=on --opt=off --ssl --dynamic-windows --win-version-min=ws08r2 CPPPATH="D:/workspace/libs/snmp/include D:/workspace/libs/sasl/include D:/workspace/libs/openssl/include D:/workspace/libs/curl/include" LIBPATH="D:/workspace/libs/snmp/lib D:/workspace/libs/sasl/lib D:/workspace/libs/openssl/lib D:/workspace/libs/curl/lib" VERBOSE=false mongod.exe mongos.exe mongo.exe

Participants:
Linked BF Score: 0

 Description   

It looks like the static initializer for ResourceId runs before that of StringData::ComparatorInterface and the process won't start:

 	mongod.exe!mongo::StringData::ComparatorInterface::hash(mongo::StringData stringToHash) mongo\base\string_data_comparator_interface.h Line 98	C++
 	mongod.exe!mongo::ResourceId::ResourceId(mongo::ResourceType type, mongo::StringData ns) mongo\db\concurrency\lock_manager.cpp Line 1119	C++
 	mongod.exe!mongo::`dynamic initializer for 'resourceIdLocalDB''() mongo\db\concurrency\lock_state.cpp Line 959	C++
 	ucrtbased.dll!_initterm()	Unknown
 	mongod.exe!__scrt_common_main_seh() Line 223	C++
 	mongod.exe!__scrt_common_main() Line 296	C++
 	mongod.exe!wmainCRTStartup() Line 17	C++
 	kernel32.dll!BaseThreadInitThunk()	Unknown
 	ntdll.dll!RtlUserThreadStart()	Unknown

This is most likely a result of the recent vtable changes.



 Comments   
Comment by Githook User [ 26/Apr/17 ]

Author:

{u'username': u'kaloianm', u'name': u'Kaloian Manassiev', u'email': u'kaloian.manassiev@mongodb.com'}

Message: SERVER-28958 Remove dependency of ResourceId on SimpleStringDataComparator
Branch: master
https://github.com/mongodb/mongo/commit/1100c4a3466ee860cdbd6ceb9d9719fe95103700

Comment by Andrew Morrow (Inactive) [ 25/Apr/17 ]

Actually, it is ASAN that can do this, not UBSAN:

https://github.com/google/sanitizers/wiki/AddressSanitizerInitializationOrderFiasco

Comment by Andrew Morrow (Inactive) [ 25/Apr/17 ]

Details on what is going wrong here:

  • LockState.cpp defines a static const ResourceId resourceIdLocalDB.
  • The constructor for ResourceId contains a call to SimpleStringDataComparator::kInstance.hash.
  • The static for SimpleStringDataComparator::kInstance.hash is declared in a separate TU, simple_string_data_comparator.cpp.

This is a classic initialization order fiasco, which is a form of undefined behavior. This UB was latent in the codebase; it just chose to exhibit symptoms recently.

Possible remedies would include:

  • Making either ResourceId or SimpleStringDataComparator literal types, so that the constants like resourceIdLocalDB or SimpleStringDataComparator::kInstance can be constexpr, so they get constant, rather than dynamic, initialization.
  • Making resourceIdLocalDB and similar into functions, containing a function scoped static ResourceId, rather than a file scoped static.

In general, we are far to profligate with our use of file scoped statics, and the codebase is rife with these errors. This is unfortunate, because it means that we can't actually enable the UBSAN check that would call this out for us.

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