[SERVER-34333] Implicitly creating db for single-collection change stream causes hang Created: 05/Apr/18  Updated: 29/Oct/23  Resolved: 05/Apr/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 3.7.4

Type: Bug Priority: Major - P3
Reporter: Charlie Swanson Assignee: Charlie Swanson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 2018-04-09
Participants:
Linked BF Score: 0

 Description   

We use the wrong lock mode for AutoGetOrCreateDB, which conflicts with the earlier lock we acquired:
We can see that this code is attempting to implicitly create the database using MODE_X, after already acquiring a lock above:

run_aggregate.cpp

349
                // Change streams can only be run against collections;
350
                // AutoGetCollectionForReadCommand will raise an error if the given namespace is a
351
                // view. A change stream may be opened on a namespace before the associated
352
                // collection is created, but only if the database already exists. If the
353
                // $changeStream was sent from mongoS then the database exists at the cluster level
354
                // even if not yet present on this shard, so we allow the $changeStream to run.
355
                AutoGetCollectionForReadCommand origNssCtx(opCtx, origNss);
356
 
357
                // Resolve the collator to either the user-specified collation or the default
358
                // collation of the collection on which $changeStream was invoked, so that we do not
359
                // end up resolving the collation on the oplog.
360
                invariant(!collatorToUse);
361
                if (!origNssCtx.getDb() && !request.isFromMongos()) {
362
                    AutoGetOrCreateDb dbLock(opCtx, origNss.db(), MODE_X);
363
                    invariant(dbLock.getDb());
364
                }
365
                Collection* origColl = origNssCtx.getCollection();
366
                collatorToUse.emplace(resolveCollator(opCtx, request, origColl));



 Comments   
Comment by Githook User [ 05/Apr/18 ]

Author:

{'email': 'charlie.swanson@mongodb.com', 'name': 'Charlie Swanson', 'username': 'cswanson310'}

Message: SERVER-34333 Avoid deadlock implicitly creating db for change stream
Branch: master
https://github.com/mongodb/mongo/commit/a5aefd87dc4e9578ccb5e0ecda425ef030aa3569

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