summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-09-28 13:24:14 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-30 14:00:54 +0000
commit427aebf681febea415a2f2db024c6e8fa65b35b1 (patch)
tree89b8b0e17742b3e92cf9c05e41e45e8bb403e12c
parent5a1c89e207987c2611c540eea3d39ac3c74bc65e (diff)
downloadmongo-427aebf681febea415a2f2db024c6e8fa65b35b1.tar.gz
SERVER-51187 Fix crash when calling yield() on CollectionPtr after restore left the instance with no collection pointer
-rw-r--r--src/mongo/db/catalog/collection.cpp7
1 files 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();
}
}