Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-633

MultiThreadedHttpConnectionManager does not properly respond to thread interrupts

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1 Beta 1
    • 3.1 RC1
    • HttpClient (classic)
    • None

    Description

      MultiThreadedHttpConnectionManager uses interrupts to notify waiting threads when a connection is ready for them. Issues arise if the threads are interrupted by someone else while they are still waiting on a thread, because doGetConnection does not remove the threads from the queue of waiting threads when they are interrupted:

      connectionPool.wait(timeToWait);

      // we have not been interrupted so we need to remove ourselves from the
      // wait queue
      hostPool.waitingThreads.remove(waitingThread); connectionPool.waitingThreads.remove(waitingThread);
      } catch (InterruptedException e)

      { // do nothing }

      finally {
      if (useTimeout)

      { endWait = System.currentTimeMillis(); timeToWait -= (endWait - startWait); }

      }

      Under ordinary circumstances, the queue maintenance is done by the notifyWaitingThread method. However, if the thread is interrupted by any other part of the system, it will (1) not actually be released, since the loop in doGetConnection will force it back to the wait, and (2) will be added the waiting thread to the queue repeatedly, which basically means that the thread will eventually receive the interrupt from notifyWaitingThread at some later point, when it is no longer actually waiting for a connection.

      This code could probably be re-architected to make it less error-prone, but the fundamental issue seems to be the use of interrupts to signal waiting threads, as opposed to something like a notify.

      Attachments

        1. mthcm-interruption.patch
          4 kB
          Michael Becke
        2. mthcm-interruption.patch
          7 kB
          Michael Becke

        Activity

          People

            mbecke Michael Becke
            johnnyb John Goodwin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: