Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-585

LaxConnPool can lose pending requests

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.0-beta8
    • 5.0-beta9
    • HttpCore
    • None

    Description

      When servicing the queue of pending lease requests, the LaxConnPool will lose a pending request if it can't be fulfilled from the pool.

       

                  while ((leaseRequest = pending.poll()) != null) {
                      if (leaseRequest.isDone()) {
                          continue;
                      }
                      final Object state = leaseRequest.getState();
                      final Deadline deadline = leaseRequest.getDeadline();
      
                      if (deadline.isExpired()) {
                          leaseRequest.failed(DeadlineTimeoutException.from(deadline));
                      } else {
                          final PoolEntry<T, C> availableEntry = getAvailableEntry(state);
                          if (availableEntry != null) {
                              addLeased(availableEntry);
                              leaseRequest.completed(availableEntry);
                          } else if (leased.size() < max) {
                              final PoolEntry<T, C> newEntry = new PoolEntry<>(route, timeToLive);
                              addLeased(newEntry);
                              leaseRequest.completed(newEntry);
                          }
                          // ***** Must do something here if there was no connection available to fulfill the request *****
                          break;
                      }
                  }
      

      The lease request is popped off the head of the queue and attempted to be fulfilled. In normal circumstances we'd expect this would succeed, because it's called from release, where we've just put a connection back in the pool. However, there's no guarantee some other thread hasn't jumped in and stolen that connection before we could grab it, so we may not be able to fulfill the lease request. In that case, we must put the lease request back on the pending queue or it will be lost, never to be completed or failed.

                          final PoolEntry<T, C> availableEntry = getAvailableEntry(state);
                          if (availableEntry != null) {
                              addLeased(availableEntry);
                              leaseRequest.completed(availableEntry);
                          } else if (leased.size() < max) {
                              final PoolEntry<T, C> newEntry = new PoolEntry<>(route, timeToLive);
                              addLeased(newEntry);
                              leaseRequest.completed(newEntry);
                          } else {
                              pending.addFirst(leaseRequest);
                          }
                          break;
      

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              linton.miller Linton Miller
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h