Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-34333

Implicitly creating db for single-collection change stream causes hang

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.4
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible
    • ALL
    • Query 2018-04-09
    • 0

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

            Assignee:
            charlie.swanson@mongodb.com Charlie Swanson
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: