You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Linton Miller (JIRA)" <ji...@apache.org> on 2019/07/27 19:53:00 UTC

[jira] [Commented] (HTTPCORE-585) LaxConnPool can lose pending requests

    [ https://issues.apache.org/jira/browse/HTTPCORE-585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16894544#comment-16894544 ] 

Linton Miller commented on HTTPCORE-585:
----------------------------------------

Suggested fix can be seen in pull request

https://github.com/coxlinton/httpcomponents-core/pull/2

> 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
>            Priority: Major
>
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org