From c1a43a1a8a81e2d6b22916303f8d42f18afd0393 Mon Sep 17 00:00:00 2001 From: cfanz Date: Wed, 2 May 2018 15:07:50 +0800 Subject: [PATCH] rgw: avoid race condition in RGWHTTPClient::wait() The cond is signaled in RGWHTTPManager's thread, which is different with the thread executing wait(), so there is a race condition. Signed-off-by: cfanz --- src/rgw/rgw_http_client.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rgw/rgw_http_client.cc b/src/rgw/rgw_http_client.cc index 25c63a7794db..2e9ac8da6f02 100644 --- a/src/rgw/rgw_http_client.cc +++ b/src/rgw/rgw_http_client.cc @@ -51,6 +51,9 @@ struct rgw_http_req_data : public RefCountedObject { int wait() { Mutex::Locker l(lock); + if (done) { + return ret; + } cond.Wait(lock); return ret; } @@ -524,11 +527,7 @@ bool RGWHTTPClient::is_done() */ int RGWHTTPClient::wait() { - if (!req_data->is_done()) { - return req_data->wait(); - } - - return req_data->ret; + return req_data->wait(); } RGWHTTPClient::~RGWHTTPClient() -- 2.47.3