From: cfanz Date: Wed, 2 May 2018 07:07:50 +0000 (+0800) Subject: rgw: avoid race condition in RGWHTTPClient::wait() X-Git-Tag: v14.1.0~1025^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F21767%2Fhead;p=ceph.git 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 --- 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()