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

Driver does not exit gracefully while in reconnecting state

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.26
    • Affects Version/s: 2.2.2
    • Component/s: None

      REPRO:
      Call MongoClient.connect and obtain a Db object (testing with a single Server)
      Bring down mongod while the app is running.
      call db.close(true, callback) and wait for callback to fire.
      Ensure that no other ref'd handles are keeping node alive yet it does not exit

      THOUGHTS:
      I did a bit of debugging and it's being kept alive by two timers (both within mongodb-core):

      1) one is issued by checkStatus() within Pool.destroy. I think this one is functioning correctly because it thinks there's something important in the work queue and it's going to admirably die trying to flush that deferred op before exiting. The question is why is something in there even though I queued no operations, and I've determined that it's an item queued by monitoringProcess in Server. Ironically it's not passing options.monitoring=true to flag the operation as not important. I've verified that disabling monitoring in the options works around this issue. This timer will otherwise keep the app active indefinitely.

      2) Pool.destroy does not call clearTimer() on self.reconnectId if it's non-null and it probably should. All that happens is we're forcing the app to stay alive until that times out and then no-ops since the state is destroying/destroyed, so seems safe to early cancel it. This only delays app shutdown by up to the retry interval, but since this is often longer than shutdown grace periods given by things like docker the effect is the same we get a "dirty" shutdown.

        1. main.js
          0.8 kB
        2. package.json
          0.3 kB

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            david.nikdel David Nikdel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: