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 4D8C7200C37 for ; Sun, 19 Mar 2017 09:45:56 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4C1D7160B7D; Sun, 19 Mar 2017 08:45:56 +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 9223A160B6E for ; Sun, 19 Mar 2017 09:45:55 +0100 (CET) Received: (qmail 46334 invoked by uid 500); 19 Mar 2017 08:45:54 -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 46320 invoked by uid 99); 19 Mar 2017 08:45:54 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Mar 2017 08:45:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id DB0F4C028B for ; Sun, 19 Mar 2017 08:45:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.898 X-Spam-Level: * X-Spam-Status: No, score=1.898 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=wso2.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 6gu7sX2q8EDx for ; Sun, 19 Mar 2017 08:45:49 +0000 (UTC) Received: from mail-pg0-f43.google.com (mail-pg0-f43.google.com [74.125.83.43]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 55D5B61EC2 for ; Sun, 19 Mar 2017 08:45:49 +0000 (UTC) Received: by mail-pg0-f43.google.com with SMTP id g2so62587239pge.3 for ; Sun, 19 Mar 2017 01:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wso2.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=HtKG9ZFSCdf2g6CmAEa8RBkBt6bh0sRmFD+crLchLf4=; b=av2UZDmdI/WpxmBDdvyI43SIYFOqO3q7aMFrSGkoJs++Lr6o5HaykY05jB5zcD455D LDrrN4Gm6n6a1j5EAfE//yZS5wIbADGNmjVFgCo3hIfyXd+w8cbqfXKBMiH+bDBH+EBt +afviUTI8/VgCnIVakhO5guxyDrkd1+vvmvms= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=HtKG9ZFSCdf2g6CmAEa8RBkBt6bh0sRmFD+crLchLf4=; b=Td+YxY8Dz/FpcNdeLSGdNA5UQEMnMBCqV99vhZrNNjSX7uNAMXL8cnZLeqriWDAiv4 VjsOw1T9fQJCZ8vyf0py9aHKlCM5KXqn9LdlOv0ro/MG44zhq0Iw62Cw2p9azLrXhSBh MS5aKpqj8JxfTKQdjoP5cUVZYrN0Xs9VEFYNnTzdkRbXV5PRa4FJeW4mNy+LzAJY+L3T MmpHzWjFZenoTFQuMuzkSXcVj2kSlZXTf18d/o1QSNNxoNfcC5a3J//WXntfDiovnDme 1dvky5naoDTHXcyb0wEBnmI+4yoC0ZMuX1rIh0zuu4LTJJloMifT+r1cUl1Ex+2wbOs9 aolg== X-Gm-Message-State: AFeK/H19GGOwVK7PABrqa9fOO+kC0bNDYp8OjRVWLdu4oNxgjcW15YchgzAqKBsyT37me2loP5n4j2R6pAsHhGMi X-Received: by 10.99.158.2 with SMTP id s2mr25307101pgd.116.1489913142287; Sun, 19 Mar 2017 01:45:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.189.13 with HTTP; Sun, 19 Mar 2017 01:45:41 -0700 (PDT) In-Reply-To: <1486721648.7141.5.camel@apache.org> References: <1486721648.7141.5.camel@apache.org> From: Shafreen Anfar Date: Sun, 19 Mar 2017 14:15:41 +0530 Message-ID: Subject: Re: Thread spinning at ChunkEncoder.write method To: HttpComponents Project Cc: djkevincr@apache.org Content-Type: multipart/alternative; boundary=f403045da7fa980e10054b116fcc archived-at: Sun, 19 Mar 2017 08:45:56 -0000 --f403045da7fa980e10054b116fcc Content-Type: text/plain; charset=UTF-8 Hi Dev, After replacing the while loop in the ChunkEncorder [1] with a if statement, we were able to solve the thread spinning issue. However, we couldn't figure out the root cause that makes the while loop spin forever. While doing a code inspection, we could see the below code segment. if (avail > 0) { if (avail < chunk) { // write no more than 'avail' bytes chunk = avail; this.lineBuffer.clear(); this.lineBuffer.append(Integer.toHexString(chunk)); this.buffer.writeLine(this.lineBuffer); final int oldlimit = src.limit(); src.limit(src.position() + chunk); this.buffer.write(src); src.limit(oldlimit); } else { // write all this.lineBuffer.clear(); this.lineBuffer.append(Integer.toHexString(chunk)); this.buffer.writeLine(this.lineBuffer); this.buffer.write(src); } this.lineBuffer.clear(); this.buffer.writeLine(this.lineBuffer); total += chunk; } if (this.buffer.length() >= this.fragHint || src.hasRemaining()) { final int bytesWritten = flushToChannel(); if (bytesWritten == 0) { break; } } In the above code segment if *avail* is less that 0, we execute the below code segment. if (this.buffer.length() >= this.fragHint || src.hasRemaining()) { final int bytesWritten = flushToChannel(); if (bytesWritten == 0) { break; } } Now, suppose *src.hasRemainning() *returns true, then it tries to flush the data to the channel. But, Do we need to do that ? The reason being if *avail *is less than 0, that means buffer doesn't have new data to write to the channel. But above code segment still tries to write data even if *avail *is less than 0. [1] https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.3.3/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkEncoder.java On Fri, Feb 10, 2017 at 3:44 PM, Oleg Kalnichevski wrote: > On Fri, 2017-02-10 at 12:58 +0530, Kevin Ratnasekera wrote: > > Hi Dev, > > > > We are recently experiencing a thread spinning issue related to HTTP > > Core > > dependency when migrating from HTTP Core version 4.2.3 to 4.3.3. Is > > there > > any known issue reported related to this? Please find the related > > partial > > thread dump taken at thread spinning. [1] > > > > HttpCore 4.3.3 release is almost 2.5 year old. 6 more releases have > been made since then with a number of bug fixes. > > Oleg > > > > [1] > > "HTTPS-Listener I/O dispatcher-35" #595 prio=5 os_prio=0 > > tid=0x00007f39904f4000 nid=0xaaee runnable [0x00007f37649c8000] > > java.lang.Thread.State: RUNNABLE > > at > > org.apache.http.impl.nio.codecs.ChunkEncoder.write(ChunkEncoder.java: > > 134) > > at org.apache.synapse.transport.passthru.Pipe.consume(Pipe.java:135) > > at > > org.apache.synapse.transport.passthru.SourceResponse.write(SourceResp > > onse.java:248) > > at > > org.apache.synapse.transport.passthru.SourceHandler.outputReady(Sourc > > eHandler.java:260) > > at > > org.apache.http.impl.nio.DefaultNHttpServerConnection.produceOutput(D > > efaultNHttpServerConnection.java:312) > > at > > org.apache.synapse.transport.http.conn.LoggingNHttpServerConnection.p > > roduceOutput(LoggingNHttpServerConnection.java:125) > > at > > org.apache.synapse.transport.passthru.ServerIODispatch.onOutputReady( > > ServerIODispatch.java:87) > > at > > org.apache.synapse.transport.passthru.ServerIODispatch.onOutputReady( > > ServerIODispatch.java:39) > > at > > org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(Abstr > > actIODispatch.java:150) > > at > > org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor > > .java:180) > > at > > org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(Abstr > > actIOReactor.java:342) > > at > > org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(Abst > > ractIOReactor.java:316) > > at > > org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIO > > Reactor.java:277) > > at > > org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor. > > java:105) > > at > > org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker. > > run(AbstractMultiworkerIOReactor.java:586) > > at java.lang.Thread.run(Thread.java:745) > > > > Locked ownable synchronizers: > > - <0x00000006e4180218> (a > > java.util.concurrent.locks.ReentrantLock$NonfairSync) > > > > Regards > > Kevin > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org > For additional commands, e-mail: dev-help@hc.apache.org > > -- Regards, *Shafreen* Software Engineer WSO2 Inc Mobile : 077-556-395-1 --f403045da7fa980e10054b116fcc--