diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-05-01 14:03:33 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-05-01 14:03:33 -0400 |
commit | 52c1fe02a0cd0f64a4d97f7c1e17792b38c67ca4 (patch) | |
tree | 50fcf20b82c91b96581f62dd0c8f98bf477157bd /src/mongo/rpc | |
parent | 46f72213f60bd74367a11aec7f02b38780ae7c3a (diff) | |
download | mongo-52c1fe02a0cd0f64a4d97f7c1e17792b38c67ca4.tar.gz |
SERVER-34141 Reset client metadata when missing in metadata
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r-- | src/mongo/rpc/metadata/client_metadata_ismaster.cpp | 23 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/client_metadata_ismaster.h | 9 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/mongo/rpc/metadata/client_metadata_ismaster.cpp b/src/mongo/rpc/metadata/client_metadata_ismaster.cpp index 3eb19853417..5f634f0338c 100644 --- a/src/mongo/rpc/metadata/client_metadata_ismaster.cpp +++ b/src/mongo/rpc/metadata/client_metadata_ismaster.cpp @@ -65,18 +65,31 @@ const boost::optional<ClientMetadata>& ClientMetadataIsMasterState::getClientMet return _clientMetadata; } -void ClientMetadataIsMasterState::setClientMetadata( - Client* client, boost::optional<ClientMetadata> clientMetadata) { +void ClientMetadataIsMasterState::setClientMetadata(Client* client, + boost::optional<ClientMetadata> clientMetadata, + bool setViaMetadata) { auto& state = get(client); stdx::lock_guard<Client> lk(*client); state._clientMetadata = std::move(clientMetadata); + state._setViaMetadata = setViaMetadata; } Status ClientMetadataIsMasterState::readFromMetadata(OperationContext* opCtx, BSONElement& element) { + auto& clientMetadataIsMasterState = ClientMetadataIsMasterState::get(opCtx->getClient()); + + // If client metadata is not present in network requests, reset the in-memory metadata to be + // blank so that the wrong + // app name is not propagated. if (element.eoo()) { + auto client = opCtx->getClient(); + + if (clientMetadataIsMasterState._setViaMetadata && !client->isInDirectClient()) { + clientMetadataIsMasterState.setClientMetadata(client, boost::none, true); + } + return Status::OK(); } @@ -86,10 +99,8 @@ Status ClientMetadataIsMasterState::readFromMetadata(OperationContext* opCtx, return swParseClientMetadata.getStatus(); } - auto& clientMetadataIsMasterState = ClientMetadataIsMasterState::get(opCtx->getClient()); - - clientMetadataIsMasterState.setClientMetadata(opCtx->getClient(), - std::move(swParseClientMetadata.getValue())); + clientMetadataIsMasterState.setClientMetadata( + opCtx->getClient(), std::move(swParseClientMetadata.getValue()), true); return Status::OK(); } diff --git a/src/mongo/rpc/metadata/client_metadata_ismaster.h b/src/mongo/rpc/metadata/client_metadata_ismaster.h index b4e38e7e430..d50f94728e4 100644 --- a/src/mongo/rpc/metadata/client_metadata_ismaster.h +++ b/src/mongo/rpc/metadata/client_metadata_ismaster.h @@ -59,7 +59,9 @@ public: /** * Set the optional client metadata object. */ - static void setClientMetadata(Client* client, boost::optional<ClientMetadata> clientMetadata); + static void setClientMetadata(Client* client, + boost::optional<ClientMetadata> clientMetadata, + bool setViaMetadata = false); /** * Check a flag to indicate that isMaster has been seen for this Client. @@ -102,6 +104,11 @@ private: // Thread-Safety: // None - must be only be read and written from the thread owning "Client". bool _hasSeenIsMaster{false}; + + // Indicates whether we have set isMaster based on metadata or via isMaster + // Thread-Safety: + // None - must be only be read and written from the thread owning "Client". + bool _setViaMetadata{false}; }; } // namespace mongo |