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

poll.poll is not threadsafe (and other problems)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      Problems with how we use poll.poll:

      • It's not thread safe, yet we use a global poll object and we don't protect calls to poll() with a mutex. If called concurrently an exception is raised. See http://bugs.python.org/issue8865.
        • Also, since the poll object is global in the network module, poll() can be called concurrently by multiple connection pools in multiple instances of MongoClient.
      • poll() can raise EINTR in versions of Python < 3.5.
      • poll() can raise exceptions for various other reasons, which will cause the fd we're polling to never be unregistered.

      Solutions:

      • Instead of using a global poll object, create a poll object per Pool, or at the very least serialize use of the global object.
      • Call poll() in a try / finally calling unregister() in the finally block
      • Catch EINTR specifically and retry the call to poll()

      While we're fixing poll, also handle EINTR being raised by select.select().

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

              Created:
              Updated:
              Resolved: