Fix Slobrok race between completion callback and scheduled task
This resolves a racing read/write on "request done" status that may
happen when RPC `HandleDone()` is invoked from one FNET thread and
`PerformTask()` is concurrently invoked from another FNET thread.
@@ -125,6 +125,7 @@ RegisterAPI::unregisterName(vespalib::stringref name)
void
RegisterAPI::handleReqDone()
{
+ std::lock_guard guard(_lock);
if (_reqDone) {
_reqDone = false;
if (_req->IsError()) {
@@ -268,11 +269,13 @@ RegisterAPI::PerformTask()
void
-RegisterAPI::RequestDone(FRT_RPCRequest *req)
+RegisterAPI::RequestDone([[maybe_unused]] FRT_RPCRequest *req)
{
+ {
+ std::lock_guard guard(_lock);
LOG_ASSERT(req == _req && !_reqDone);
- (void) req;
_reqDone = true;
+ }
ScheduleNow();
}
