Skip to content

Commit 6ba58bb

Browse files
vinser52guptask
authored andcommitted
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 07620ee commit 6ba58bb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cachelib/allocator/Handle.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ struct ReadHandleImpl {
402402
}
403403
}
404404

405+
protected:
406+
friend class ReadHandleImpl;
407+
// Method used only by ReadHandleImpl ctor
408+
void discard() {
409+
it_.store(nullptr, std::memory_order_relaxed);
410+
}
405411
private:
406412
// we are waiting on Item* to be set to a value. One of the valid values is
407413
// nullptr. So choose something that we dont expect to indicate a ptr
@@ -485,6 +491,7 @@ struct ReadHandleImpl {
485491
if (it_ && it_->isIncomplete()) {
486492
waitContext_ = std::make_shared<ItemWaitContext>(alloc);
487493
if (!alloc_->addWaitContextForMovingItem(it->getKey(), waitContext_)) {
494+
waitContext_->discard();
488495
waitContext_.reset();
489496
}
490497
}

0 commit comments

Comments
 (0)