summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/rpc/metadata/client_metadata.cpp6
-rw-r--r--src/mongo/rpc/metadata/client_metadata.h5
2 files changed, 6 insertions, 5 deletions
diff --git a/src/mongo/rpc/metadata/client_metadata.cpp b/src/mongo/rpc/metadata/client_metadata.cpp
index a4b78080ec9..ccd11fb542e 100644
--- a/src/mongo/rpc/metadata/client_metadata.cpp
+++ b/src/mongo/rpc/metadata/client_metadata.cpp
@@ -472,7 +472,8 @@ bool ClientMetadata::tryFinalize(Client* client) {
const ClientMetadata* ClientMetadata::getForClient(Client* client) noexcept {
auto& state = getClientState(client);
- if (!state.isFinalized || !state.meta) {
+ if (!state.meta) {
+ // If we haven't finalized, it's still okay to return our existing value.
return nullptr;
}
return &state.meta.get();
@@ -514,7 +515,7 @@ void ClientMetadata::setFromMetadataForOperation(OperationContext* opCtx, BSONEl
auto wasFinalized = std::exchange(state.isFinalized, true);
uassert(ErrorCodes::ClientMetadataCannotBeMutated,
"The client metadata document may only be set once per operation",
- !wasFinalized);
+ !state.meta && !wasFinalized);
state.meta = ClientMetadata::readFromMetadata(elem);
}
@@ -541,6 +542,7 @@ 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 ff17cf60720..3742cf21a35 100644
--- a/src/mongo/rpc/metadata/client_metadata.h
+++ b/src/mongo/rpc/metadata/client_metadata.h
@@ -90,9 +90,8 @@ public:
/**
* Get the ClientMetadata for the Client.
*
- * This function may return nullptr for either of two reasons:
- * - The ClientMetadata hasn't been finalized yet via tryFinalize().
- * - The ClientMetadata wasn't provided at all.
+ * This function may return nullptr if there was no ClientMetadata provided for the
+ * Client.
*
* The pointer to ClientMetadata is valid to use if:
* - You hold the Client lock.