Skip to content

Commit c904851

Browse files
committed
MB-31544: Fix race condition adding external auth requests
Lock the task mutex while we've got the external auth mutex so that the external auth thread can't get the task mutex before Task::execute returns Change-Id: I00bf04b9f9faa6ab6f4cb4a3e218aac95572364a Reviewed-on: http://review.couchbase.org/100302 Tested-by: Build Bot <[email protected]> Reviewed-by: Daniel Owen <[email protected]>
1 parent 4e37ea4 commit c904851

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

daemon/external_auth_manager_thread.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,19 @@ void ExternalAuthManagerThread::remove(Connection& connection) {
9797
}
9898

9999
void ExternalAuthManagerThread::enqueueRequest(StartSaslAuthTask& request) {
100+
// We need to make sure that the lock ordering for these
101+
// mutexes is the same. Let's unlock the task (and the executor thread
102+
// is currently blocked waiting for this method to return. It won't
103+
// touch the mutex until we return.
104+
// Then we'll grab the external auth manager mutex and get our mutex
105+
// back (no one else knows about that mutex yet so it should never
106+
// block). Then we'll just release the external auth manager lock,
107+
// and the external auth thread may start processing these events,
108+
// but it'll have to wait until we release the request mutex
109+
// before it may signal the task.
110+
request.getMutex().unlock();
100111
std::lock_guard<std::mutex> guard(mutex);
112+
request.getMutex().lock();
101113
incomingRequests.push(&request);
102114
condition_variable.notify_all();
103115
}

daemon/start_sasl_auth_task.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ Task::Status StartSaslAuthTask::internal_auth() {
7979
// We can't hold this lock when we're trying to enqueue the
8080
// request
8181
internal = false;
82-
getMutex().unlock();
8382
externalAuthManager->enqueueRequest(*this);
84-
getMutex().lock();
8583
}
8684

8785
return internal ? Status::Finished : Status::Continue;

0 commit comments

Comments
 (0)