From 427aebf681febea415a2f2db024c6e8fa65b35b1 Mon Sep 17 00:00:00 2001 From: Henrik Edin Date: Mon, 28 Sep 2020 13:24:14 -0400 Subject: SERVER-51187 Fix crash when calling yield() on CollectionPtr after restore left the instance with no collection pointer --- src/mongo/db/catalog/collection.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index 36f73778483..1341599ab65 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -107,20 +107,23 @@ bool CollectionPtr::_canYield() const { } void CollectionPtr::yield() const { - if (_canYield()) { + // Yield if we are yieldable and have a valid collection + if (_canYield() && _collection) { _uuid = _collection->uuid(); _ns = _collection->ns(); _collection = nullptr; } } void CollectionPtr::restore() const { - if (_canYield()) { + // Restore from yield if we are yieldable and if uuid was set in a previous yield. + if (_canYield() && _uuid) { // We may only do yield restore when we were holding locks that was yielded so we need to // refresh from the catalog to make sure we have a valid collection pointer. auto coll = _catalogLookup()(_opCtx, *_uuid, _catalogEpoch); if (coll && coll->ns() == _ns) { _collection = coll.get(); } + _uuid.reset(); } } -- cgit v1.2.1