[SERVER-42080] Verify that stdx::unordered_map/unordered_set throws from at() Created: 03/Jul/19  Updated: 29/Oct/23  Resolved: 15/Aug/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.3.1

Type: Improvement Priority: Major - P3
Reporter: Benjamin Caimano (Inactive) Assignee: ADAM Martin (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Gantt Dependency
has to be done after SERVER-42620 pull abseil-cpp from mongodb-forks Closed
Backwards Compatibility: Fully Compatible
Sprint: Dev Tools 2019-08-12, Dev Tools 2019-08-26
Participants:

 Description   

Abseil calls abort() instead of throwing std::out_of_range. We should patch this at least in our vendoring. We could simply throw std::out_of_range like reasonable people or use abseil's throw delegate.



 Comments   
Comment by Githook User [ 15/Aug/19 ]

Author:

{'name': 'ADAM David Alan Martin', 'email': 'adam.martin@10gen.com', 'username': 'adamlsd'}

Message: SERVER-42080 `stdx::unordered_map<...>::at` must throw.

Added a test to check that this happens.
Branch: master
https://github.com/mongodb/mongo/commit/f78ba67112fa95a54cfe6d94c33b11e389efdc44

Comment by Mira Carey [ 08/Jul/19 ]

Yeah, this isn't move ops. It's what happens when you do:

try {
  std::unordered_map<int, int> map;
  return map.at(42);
} catch (...) {}

I.e. table stakes for basic functionality, where a basic idiom is implemented incorrectly.

For what it's worth, I can see codepaths in our code that are broken because we'rd on abseil. See: https://github.com/mongodb/mongo/blob/7eab0b598578261829a7adce6330ae7eff2894a1/src/mongo/shell/kms.cpp#L66

std::unique_ptr<KMSService> KMSServiceController::createFromClient(StringData kmsProvider,
                                                                   const BSONObj& config) {
    KMSProviderEnum provider =
        KMSProvider_parse(IDLParserErrorContext("client fle options"), kmsProvider);
 
    auto service = _factories.at(provider)->create(config);
    uassert(51192, str::stream() << "Cannot find client kms provider " << kmsProvider, service);
    return service;
}

Note that _factories is a stdx::unordered_map. If that pointed to std, this function would throw (as it clearly expects to given the uassert) when seeing provider for the first time. On abseil it terminates the process.

Comment by Billy Donahue [ 08/Jul/19 ]

They're willing to invest in exception safety and compliance*.

h ttps://github.com/abseil/abseil-cpp/issues/37

 

* They do have a nonstandard "stance" on nothrow move ops, but I don't think that's what we're talking about here.

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