Move synchronous policy init inside lock
Avoids a race when multiple threads try to synchronously initialize
a MessageBus policy.
This resolves a TSan warning.
@@ -71,13 +71,13 @@ currentPolicyInitError(vespalib::stringref error) {
void
AsyncInitializationPolicy::select(mbus::RoutingContext& context)
{
+ {
+ std::lock_guard lock(_lock);
+
if (_syncInit && _state != State::DONE) {
initSynchronous();
}
- {
- std::lock_guard lock(_lock);
-
if (_state == State::NOT_STARTED || _state == State::FAILED) {
// Only 1 task may be queued to the executor at any point in time.
// This is maintained by only scheduling a task when either no task
