Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4490

Reference count check is not atomic with release

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.5.0
    • Affects Version/s: None
    • Component/s: Reactive Streams
    • None
    • Fully Compatible
    • Not Needed

      This race condition showed up in a unit test but it seems possible, though rare, that it could affect an application using the driver.

      The issue is that DefaultServer.AsyncOperationCountTrackingConnection#release is not synchronized, and it some circumstances be called concurrently. So if the timing is just wrong, multiple concurrent calls can observe a 0 reference count, resulting in the operation count decrementing below 0, which in turn causes an assertion to fire.

      There are several approaches to fixing this, but the cleanest is to change the RefererenceCounted#release method to atomically return the decremented count and compare the returned value to 0.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: