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

Incorrect read timeout handling causes connection closing

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.2.0, 3.12.8
    • Affects Version/s: 4.0.5, 4.1.0
    • Component/s: Async
    • None
    • Fully Compatible
    • Not Needed

      NettyStream handles timeouts using  ReadTimeoutHandler. It schedules and cancels timeout operations in various places (e.g. here or here) and does so in an asynchronous way by submitting Tasks to Executors. The code in NettyStream (especially in readAsync method) and in ReadTimeoutHandler assumes that cancellations happen after scheduling a task, but since they are executed concurrently in multiple threads we may sometimes have a situation (as we do in our project) that a scheduled timeout task is not cancelled since the cancellation is effectively done before the task is scheduled (i.e. removeTimeout is called BEFORE scheduleTimeout).

       

      This improper handling of timeouts causes connections to be treated as invalid (STALE) when a "bogus" timeout occurs and because of the driver policy all other connections to the same server will be marked as invalid.

       

      In the near future I'll provide a PR with a solution to that problem.

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            kaminski.konrad@gmail.com Konrad Kamiński
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: