Skip to content

Commit c95b2b3

Browse files
committed
Fix issue with "Destorying an unresolved handle"
The issue happened when ReadHandleImpl ctor needs to destroy waitContext_ because addWaitContextForMovingItem() returns false. So before destroying waitContext_ we are calling discard method to notify ~ItemWaitContext() that Item is ready.
1 parent 043df5f commit c95b2b3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cachelib/allocator/Handle.h

+7
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ struct ReadHandleImpl {
392392
}
393393
}
394394

395+
protected:
396+
friend class ReadHandleImpl;
397+
// Method used only by ReadHandleImpl ctor
398+
void discard() {
399+
it_.store(nullptr, std::memory_order_relaxed);
400+
}
395401
private:
396402
// we are waiting on Item* to be set to a value. One of the valid values is
397403
// nullptr. So choose something that we dont expect to indicate a ptr
@@ -475,6 +481,7 @@ struct ReadHandleImpl {
475481
if (it_ && it_->isIncomplete()) {
476482
waitContext_ = std::make_shared<ItemWaitContext>(alloc);
477483
if (!alloc_->addWaitContextForMovingItem(it->getKey(), waitContext_)) {
484+
waitContext_->discard();
478485
waitContext_.reset();
479486
}
480487
}

0 commit comments

Comments
 (0)