Linton Miller created HTTPCORE-585:
--------------------------------------
Summary: LaxConnPool can lose pending requests
Key: HTTPCORE-585
URL: https://issues.apache.org/jira/browse/HTTPCORE-585
Project: HttpComponents HttpCore
Issue Type: Bug
Components: HttpCore
Affects Versions: 5.0-beta8
Reporter: Linton Miller
When servicing the queue of pending lease requests, the LaxConnPool will lose a
pending request if it can't be fulfilled from the pool.
{code:java}
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;
}
}
{code}
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.
{code:java}
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;
{code}
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]