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
- links to