[SERVER-25681] ViewDefinitions obtained from ViewCatalog are freed on reload Created: 18/Aug/16  Updated: 02/Sep/16  Resolved: 19/Aug/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.3.12

Type: Bug Priority: Critical - P2
Reporter: Kyle Suarez Assignee: Kyle Suarez
Resolution: Done Votes: 0
Labels: read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Integration 2016-08-29
Participants:

 Description   
  1. Thread A calls ViewCatalog::lookup() and obtains a raw ViewDefinition*.
  2. Thread B inserts a valid view directly into system.views. ViewCatalog::_valid is marked as false. (Note that this insert is possible because Thread A locks the database in MODE_IS, which does not conflict with a MODE_IX lock obtained by Thread B. Other commands that modify the view definitions require a MODE_X lock; i.e. create, collMod, drop.)
  3. Thread C calls a method of ViewCatalog, which implicitly reloads the catalog, clearing the old ViewMap, freeing all of the old ViewDefinitions.
  4. All iterators to the old ViewMap are now invalidated and all the ViewDefinition pointers have been freed, but Thread A might still be holding onto the ViewDefinition and may try to use it, resulting in undefined behavior.


 Comments   
Comment by Githook User [ 19/Aug/16 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-25681 fix ViewCatalog reload race

Changes ViewCatalog::lookup() to return a shared_ptr<ViewDefinition> rather than
a bare pointer, allowing the view definitions to persist even if the ViewCatalog
is reloaded.
Branch: master
https://github.com/mongodb/mongo/commit/1343dfdac48d148b0a72fc9aa4af23a7191082cd

Generated at Thu Feb 08 04:09:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.