Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6D8102009DC for ; Tue, 2 May 2017 15:20:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6C07A160BAC; Tue, 2 May 2017 13:20:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B3531160BA1 for ; Tue, 2 May 2017 15:20:08 +0200 (CEST) Received: (qmail 24218 invoked by uid 500); 2 May 2017 13:20:07 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 24207 invoked by uid 99); 2 May 2017 13:20:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 May 2017 13:20:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 6029EC118B for ; Tue, 2 May 2017 13:20:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 1p4oxmGjWSPe for ; Tue, 2 May 2017 13:20:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 06BF65F36F for ; Tue, 2 May 2017 13:20:06 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id DD5C3E0BDD for ; Tue, 2 May 2017 13:20:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 27E9021DE5 for ; Tue, 2 May 2017 13:20:04 +0000 (UTC) Date: Tue, 2 May 2017 13:20:04 +0000 (UTC) From: "Oleg Kalnichevski (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (HTTPCLIENT-1165) Cache allows multipe requests to retrieve the same cacheable resource from the server in multithreaded environment due to lack of proper locking MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 02 May 2017 13:20:09 -0000 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1165?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Oleg Kalnichevski updated HTTPCLIENT-1165: ------------------------------------------ Labels: stuck volunteers-wanted (was: ) Fix Version/s: (was: Future) Stuck > Cache allows multipe requests to retrieve the same cacheable resource from the server in multithreaded environment due to lack of proper locking > ------------------------------------------------------------------------------------------------------------------------------------------------ > > Key: HTTPCLIENT-1165 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1165 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpCache > Affects Versions: Snapshot > Reporter: Manish Tripathi > Labels: stuck, volunteers-wanted > Fix For: Stuck > > > Consider the following scenario: > Two separate threads are launched at the same time with identical Http requests through CachingHttpClient. > Both threads look up the same URI in the cache at [almost] the same time and find no cached response for that URI. > Both threads fall back to backend HttpClient and make identical requests to the server. > Both threads retrieve the resource and attempt to store it in the cache. > The same resource gets retrieved from the server twice and is stored in the cache twice. > Obviously, the described algorithm is inefficient > Suggested fix: introduce read-write locking mechanism which would block multiple requests to retrieve the same URI until one of the concurrent requests has either received a response header indicating that the response is not cacheable, or until cacheable response has been fully retrieved and stored in the cache. The proposed pseudo-code follows: > cachingClient.execute(url) { > if (lock_count(url)>0) > lock=lockingFactory.acquireReadLock(url); > else > lock=lockingFactory.acquireWriteLock(url); > response=satisfyFromCache(url); > if (response==null) { > if (lock.isReadLock()) { lock.release(); lock=lockingFactory.acquireWriteLock(url); } > response=satisfyFromServerAndStoreInCache(url); > } > lock.release(); > return response; > } > where lockingFactory instance is shared by multiple instances of CachingHttpClient. -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org