summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@10gen.com>2020-12-15 19:18:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-20 00:08:31 +0000
commit641bdc9e26743d4c792765e3020ba1cd161cf3c2 (patch)
tree4d8d14466e7b3bdfcde080e4f79380ba0b5d3137
parent55499d373701e0dbc8d7c96935290ac08900ea07 (diff)
downloadmongo-641bdc9e26743d4c792765e3020ba1cd161cf3c2.tar.gz
SERVER-53334 User assert instead of invariant in ClientMetadata
(cherry picked from commit 84cb1c85a16cd62a0fb8bec1958262adb002ae8d)
-rw-r--r--src/mongo/rpc/metadata/client_metadata.cpp20
-rw-r--r--src/mongo/rpc/metadata/client_metadata.h9
2 files changed, 17 insertions, 12 deletions
diff --git a/src/mongo/rpc/metadata/client_metadata.cpp b/src/mongo/rpc/metadata/client_metadata.cpp
index faa62c32102..6da007939b9 100644
--- a/src/mongo/rpc/metadata/client_metadata.cpp
+++ b/src/mongo/rpc/metadata/client_metadata.cpp
@@ -443,7 +443,10 @@ const BSONObj& ClientMetadata::getDocument() const {
}
void ClientMetadata::logClientMetadata(Client* client) const {
- invariant(!getDocument().isEmpty());
+ if (getDocument().isEmpty()) {
+ return;
+ }
+
log() << "received client metadata from " << client->getRemote().toString() << " "
<< client->desc() << ": " << getDocument();
}
@@ -519,16 +522,16 @@ void ClientMetadata::setFromMetadataForOperation(OperationContext* opCtx, BSONEl
}
void ClientMetadata::setFromMetadata(Client* client, BSONElement& elem) {
- auto& state = getClientState(client);
+ if (elem.eoo()) {
+ return;
+ }
+ auto& state = getClientState(client);
{
auto lk = stdx::lock_guard(*client);
- if (state.isFinalized) {
- uassert(ErrorCodes::ClientMetadataCannotBeMutated,
- "The client metadata document may only be sent in the first hello",
- elem.eoo());
- return;
- }
+ uassert(ErrorCodes::ClientMetadataCannotBeMutated,
+ "The client metadata document may only be sent in the first hello",
+ !state.isFinalized);
}
auto meta = ClientMetadata::readFromMetadata(elem);
@@ -540,7 +543,6 @@ void ClientMetadata::setFromMetadata(Client* client, BSONElement& elem) {
}
auto lk = stdx::lock_guard(*client);
- invariant(!state.meta, "ClientMetadata was previously set, it should be set precisely once");
state.meta = std::move(meta);
}
diff --git a/src/mongo/rpc/metadata/client_metadata.h b/src/mongo/rpc/metadata/client_metadata.h
index 294a88815ec..c1c837386d6 100644
--- a/src/mongo/rpc/metadata/client_metadata.h
+++ b/src/mongo/rpc/metadata/client_metadata.h
@@ -203,7 +203,8 @@ public:
*
* Once this function is called, no future hello can mutate the ClientMetadata.
*
- * This function takes the Client lock.
+ * This function is only valid to invoke if you are on the Client's thread. This function takes
+ * the Client lock.
*/
static bool tryFinalize(Client* client);
@@ -213,7 +214,8 @@ public:
* This function throws if the ClientMetadata has already been finalized but the BSONElement is
* an object. ClientMetadata is allowed to be set via the first hello only.
*
- * This function takes the Client lock.
+ * This function is only valid to invoke if you are on the Client's thread. This function takes
+ * the Client lock.
*/
static void setFromMetadata(Client* client, BSONElement& elem);
@@ -222,7 +224,8 @@ public:
*
* This function throws if called more than once for the same OperationContext.
*
- * This function takes the Client lock.
+ * This function is only valid to invoke if you are on the Client's thread. This function takes
+ * the Client lock.
*/
static void setFromMetadataForOperation(OperationContext* opCtx, BSONElement& elem);