summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-11-29 15:41:04 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-11-29 16:16:44 +0000
commit766e14cc7a3fea7dfd5bbc9b549c2bfd9a838efe (patch)
treea7f2002d6b41b0f8528858289acf0efb9c315ad7 /storage
parent7fbfecba694f1665d5c00bd504086a49898f8bb2 (diff)
Defer MBus DestinationSession registration during content node init
Creating a `DestinationSession` that is immediately registered as available for business means we may theoretically start receiving messages over the session even before the call returns to the caller. Either way there would be no memory barrier that ensures that `_messageBusSession` would be fully visible to the MessageBus threads (since it's written after return). To avoid this sneaky scenario, defer registration (and thus introduce a barrier) until _after_ we've initialized our internal member variables. This addresses a TSan warning.
Diffstat (limited to 'storage')
-rw-r--r--storage/src/vespa/storage/storageserver/communicationmanager.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/storage/src/vespa/storage/storageserver/communicationmanager.cpp b/storage/src/vespa/storage/storageserver/communicationmanager.cpp
index 621f8a2ecc0..4458bf8a92d 100644
--- a/storage/src/vespa/storage/storageserver/communicationmanager.cpp
+++ b/storage/src/vespa/storage/storageserver/communicationmanager.cpp
@@ -396,6 +396,7 @@ void CommunicationManager::configure(std::unique_ptr<CommunicationManagerConfig>
mbus::DestinationSessionParams dstParams;
dstParams.setName("default");
dstParams.setBroadcastName(true);
+ dstParams.defer_registration(true); // Deferred session registration; see rationale below
dstParams.setMessageHandler(*this);
_messageBusSession = _mbus->getMessageBus().createDestinationSession(dstParams);
@@ -403,6 +404,14 @@ void CommunicationManager::configure(std::unique_ptr<CommunicationManagerConfig>
srcParams.setThrottlePolicy(mbus::IThrottlePolicy::SP());
srcParams.setReplyHandler(*this);
_sourceSession = _mbus->getMessageBus().createSourceSession(srcParams);
+
+ // Creating a DestinationSession that is immediately registered as available for business
+ // means we may theoretically start receiving messages over the session even before the call returns
+ // to the caller. Either way there would be no memory barrier that ensures that _messageBusSession
+ // would be fully visible to the MessageBus threads (since it's written after return).
+ // To avoid this sneaky scenario, defer registration (and thus introduce a barrier) until
+ // _after_ we've initialized our internal member variables.
+ _messageBusSession->register_session_deferred();
}
}