[SERVER-48116] init-order bug inside pcrecpp Created: 11/May/20  Updated: 29/Oct/23  Resolved: 19/May/20

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

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:
Backports
Problem/Incident
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.4
Sprint: Service arch 2020-05-18, Service arch 2020-06-01
Participants:
Linked BF Score: 50

 Description   

The fiasco is within pcrecpp.

If we make an RE object too soon, it will reference some internal global state in the RE::Init pseudo-constructor, which might not yet be initialized. This benchmark is getting ProcessInfo at static init time, which gathers a lot of process metadata.

BENCHMARK_REGISTER_F(CacheLatencyTest, BM_CacheLatency)
    ->RangeMultiplier(2 * 1024)
    // Loop over arrays of different sizes to test the L2, L3, and RAM latency.
    ->Range(256 * 1024, 4096 * 1024)
    ->ThreadRange(1, ProcessInfo::getNumAvailableCores());

This call to getNumAvailableCores is the culprit. That function isn't currently safe at static init time.
It incidentally causes an RE to be made for parsing the /proc/mountinfo file, before RE's static default_options object is initialized.
This is a pcrecpp internal bug, and a fix should be upstreamed.

https://github.com/vmg/pcre/blob/master/pcrecpp.cc#L86

static RE_Options default_options;

referring to this in a static initializer is an init-order fiasco trigger.



 Comments   
Comment by Githook User [ 19/May/20 ]

Author:

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

Message: SERVER-48116 fix init-order bug in pcrecpp::RE::Init
Branch: master
https://github.com/mongodb/mongo/commit/e25d6c9c19e1897497ef07fcbb656bd4c17be349

Comment by Billy Donahue [ 19/May/20 ]

CR https://mongodbcr.appspot.com/589400001

Comment by Billy Donahue [ 14/May/20 ]

reopening to pursue better fix suggested by upstream bugzilla response.

Comment by Billy Donahue [ 14/May/20 ]

Actually upstream suggested a simpler fix. The RE_Options is just three ints, initialized to zero.
There's no reason at all to have a static instance of it. Will re-fix.

Comment by Billy Donahue [ 13/May/20 ]

Filed an upstream bug report https://bugs.exim.org/show_bug.cgi?id=2575

Comment by Billy Donahue [ 13/May/20 ]

It's not showing up here for some reason, but the backport to 4.4 is:
https://github.com/mongodb/mongo/commit/a585cd2b6655af2542cdd153c4e9852d270b497d

Comment by Githook User [ 13/May/20 ]

Author:

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

Message: SERVER-48116 fix init-order bug in pcrecpp::RE::Init
Branch: master
https://github.com/mongodb/mongo/commit/cb3f49285f8a5663244f94d89e56c2f28f7ae685

Comment by Billy Donahue [ 11/May/20 ]

CR https://mongodbcr.appspot.com/606070016/

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