Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4348

MongoClient opened before fork warning is never raised

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.7
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • 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?

      In PYTHON-2484 we added a MongoClient._after_fork() hook that resets the topology state in hopes of making the client slightly more fork-safe. We later discovered in PYTHON-3406 that network I/O + threads in general is not fork-safe and we attempted to reinstate the warning:

                  warnings.warn(
                      "MongoClient opened before fork. May not be entirely fork-safe, "
                      "proceed with caution. See PyMongo's documentation for details: "
                      "https://pymongo.readthedocs.io/en/stable/faq.html#"
                      "is-pymongo-fork-safe",
                      stacklevel=2,
                  )
      

      https://github.com/mongodb/mongo-python-driver/blob/ebb94b669ec2be5968f2cdfd7928b68808539216/pymongo/topology.py#L190-L196

      However, the MongoClient._after_fork() makes it such that the "MongoClient opened before fork" warning will never appear.

      Note that in Python 3.12 the interpreter itself issues this warning:

      /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/popen_fork.py:66: DeprecationWarning: This process (pid=96002) is multi-threaded, use of fork() may lead to deadlocks in the child.
      

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: