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

Infinite loop on Windows due to a bug in require_optional package

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 3.6.6
    • Affects Version/s: 3.6.3
    • Component/s: None

      Problem Description

      On a windows machine without, for example, snappy in the require path, mongodb ends up in an infinite loop when trying to optionally require snappy.

      This is beacuse a bug in the package require_optional

      The search starts in the given path, if the file isn't found it continues with the parent folder, and so on in a loop. The stop criterias for the loop are

      1. The file is found
      2. The current path equals '/'

      It never matches the second critera on a Windows machine, where paths starts with the drive letter, for example 'C:\'

      See bug for description:

      https://github.com/christkv/require_optional/issues/11

      A PR for this has been available since Nov 9 2018 without being merge

      https://github.com/christkv/require_optional/pull/8 

      I think it's safe to say the package is dead!

      The infinite loop happens directly in the require('mongodb') call.

      Possible fix

      Switch to the package require-optional: https://www.npmjs.com/package/require-optional 
      The mongodb package uses require_optional with only one parameter. This is functionally equal to calling require-optional with only one parameter, so a search and replace for:

      require('require_optional')

      to 

      require('require-optional')

      is enough.

      I've successfully monkey patched my system's node_modules/mongodb this way.

       

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            hakan.canberger@ving.se Håkan Canberger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: