Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A0935E7A1 for ; Mon, 17 Dec 2012 03:07:45 +0000 (UTC) Received: (qmail 40480 invoked by uid 500); 17 Dec 2012 03:07:44 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 40190 invoked by uid 500); 17 Dec 2012 03:07:44 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 40145 invoked by uid 99); 17 Dec 2012 03:07:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Dec 2012 03:07:42 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of stephen.butler@gmail.com designates 209.85.210.179 as permitted sender) Received: from [209.85.210.179] (HELO mail-ia0-f179.google.com) (209.85.210.179) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Dec 2012 03:07:36 +0000 Received: by mail-ia0-f179.google.com with SMTP id o25so5073144iad.10 for ; Sun, 16 Dec 2012 19:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=BK/NXCYR7lvZBwdL5Bx7dcA+39UEPPLdyIjKgDVR/8Y=; b=PCPJWcIHwm2712r8oAKjRg2pqhI+nskwCZKZwPJMBJv4R225+yt3uy24MVckKk6YtV JE7Qwg7IV2GzM5IE3gmVda7enkSVlbhv4hcxhG6h8+UKc8nEBUqS+ZzO+kIXYgcSNo/Y 9cA4FqeAU6GGpHMv8m809Fg6fF3gH4bh9WZxVaeeBZQ807i6EfxJHm3SUzTeXCkOKplr xvDkdEiNagOq/Fx9YdPjfSZkmRdBfdk2Qp2EKKixq03kzGBgR50hAub/B0WGmKugf4q9 p0Hj6hV4NNfoh5w/BhqqOAb4dr6TT0a4vn/P589jd2cUTqFdgYRM+EIdKP471s7j3VAb LNjw== MIME-Version: 1.0 Received: by 10.50.12.169 with SMTP id z9mr7954570igb.40.1355713635815; Sun, 16 Dec 2012 19:07:15 -0800 (PST) Received: by 10.64.19.65 with HTTP; Sun, 16 Dec 2012 19:07:15 -0800 (PST) In-Reply-To: References: Date: Sun, 16 Dec 2012 21:07:15 -0600 Message-ID: Subject: Re: Right way to timeout From: "Stephen J. Butler" To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=14dae93409bbae0f9304d103ade7 X-Virus-Checked: Checked by ClamAV on apache.org --14dae93409bbae0f9304d103ade7 Content-Type: text/plain; charset=ISO-8859-1 setConnectionTimeout() only sets a timeout on the initial TCP connection request. And setSoTimeout() sets a timeout on the socket operations. But if the server is responding to normal TCP packets (whether they have any payload or not) then this timeout will never be reached. If you want to set a timeout on an overall HTTP operation you should setup your own thread and call .abort() on the request (this method is thread-safe). For example, I use this class and create a new instance of it for every request I want to timeout. When I get a response, I interrupt my timeout thread. http://pastebin.com/sRZdZuKx On Sun, Dec 16, 2012 at 7:11 PM, Jean-Marc Spaggiari < jean-marc@spaggiari.org> wrote: > Hi, > > What's the "right" way to configure the timeout with HttpClient 4.2.1? > > Here is what I'm doing: > > HttpParams params = client.getParams(); > HttpConnectionParams.setConnectionTimeout(params, > 30000); > HttpConnectionParams.setSoTimeout(params, 30000); > result.result = client.execute (method); > > But I don't think it's working. Sometime it's taking way more than 30 > seconds. > > How should I proceed? > > I have setup a thread to kill the calls when they are taking to much time > > Thanks, > > JM > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org > For additional commands, e-mail: httpclient-users-help@hc.apache.org > > --14dae93409bbae0f9304d103ade7--