Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-6151

MongoClient connect does not keep Node.js running

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.6.1
    • Affects Version/s: 6.6.0
    • Component/s: None
    • 2
    • Needed
    • Hide

      Create a copy of the Kickoff Template with the issue key (NODE-XXX) in the filename and share a link to the new doc via this field.

      Show
      Create a copy of the Kickoff Template with the issue key (NODE-XXX) in the filename and share a link to the new doc via this field.
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Use Case

      As a MongoDB user who is calling MongoClient.connect on an un-selectable cluster
      I want MongoClient.connect to hold the Node.js process open until serverSelectionTimeoutMS expires
      So that I can see the rejected error.

      The new Timeout abstraction unref-s it's timer which may make sense for CSOT. On your very first connect call the serverSelection ref-ed setTimeout call is what keeps Node.js open.

      User Impact

      • The following sample code exits immediately with "Warning: Detected unsettled top-level await"
      import { MongoClient } from 'mongodb';
      
      // real set name: repl0
      const cs = 'mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/&replicaSet=asdf';
      process.on('exit', () => console.log('exiting'));
      const client = await MongoClient.connect(cs);
      console.log('connected');
      await client.close();
      

      Dependencies

      • serverSelectionTimeoutMS logic
      • Timeout ref/unref

      Unknowns

      • None

      Acceptance Criteria

      Implementation Requirements

      • Ref the timer in Timeout
        • If it is possible only do this when we are connecting for the first time? (check the MongoClient) otherwise do it always and revisit ref-ing / clearing for CSOT

      Testing Requirements

      • Determine: What is the best programmatic way to determine if Node.js would exit?
        • process _activeHandles? process.on('beforeExit')
      • Assert MongoClient.connect keeps Node.js running until it succeeds or fails.

      Documentation Requirements

      • None

      Follow Up Requirements

      • Consider refactoring auto-connect: monitors should be "always on". Is this caused by the process.nextTick that surrounds requestCheck? if we called requestCheck directly then would server selection have created sockets thus keeping Node open?
      • Add testing to verify that this behaviour does not return in subsequent changes (NODE-6152)

            Assignee:
            warren.james@mongodb.com Warren James
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: