Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 15144 invoked from network); 2 Mar 2010 02:47:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Mar 2010 02:47:47 -0000 Received: (qmail 66194 invoked by uid 500); 2 Mar 2010 02:47:42 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 66053 invoked by uid 500); 2 Mar 2010 02:47:41 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 66044 invoked by uid 99); 2 Mar 2010 02:47:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 02:47:41 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of haeloong@gmail.com designates 209.85.160.45 as permitted sender) Received: from [209.85.160.45] (HELO mail-pw0-f45.google.com) (209.85.160.45) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 02:47:35 +0000 Received: by pwi4 with SMTP id 4so1859552pwi.18 for ; Mon, 01 Mar 2010 18:47:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=PtoIGnjuQcZvn8TXGNll8UWxUSW0C0IdaqYDCnf/hNA=; b=etO4XD5mjX5b2XDxiK3VpMVPDjf0SMXP1mBel9OJfMbL46e4qifTiL3qQAvc0oMRac dyj8CVtJxlu9pgnHVnL0Ib3q9K1+st4YMsxbGJzNvh0rr2V2Q9vsRnCp3zj2RPrIBxe1 Z9qUMlaIdlqNG1pyGvTJb1hYqWptD+2+YLrKs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=cXW8HPxaMuvmZP631ZmakaHfXK4aBNBMuzEfAJrV/NSoyzhVLhyt1UbMddCNj4679h o1Syb+n5CEoFv/GbSgJoA5+S1TUhJqRmRG0F9+hdmkSJeDv6hFMaVIjPRsoPwBEMLRw7 MpbSZ1wm96oSghsba5/7j9CK/dTWrRn6N0Jd4= MIME-Version: 1.0 Received: by 10.141.106.11 with SMTP id i11mr2931339rvm.213.1267498034820; Mon, 01 Mar 2010 18:47:14 -0800 (PST) In-Reply-To: <7e5f6ff51003011827v401d81ffk167ed454b2114164@mail.gmail.com> References: <7e5f6ff51003011827v401d81ffk167ed454b2114164@mail.gmail.com> Date: Tue, 2 Mar 2010 10:47:14 +0800 Message-ID: <9c483daa1003011847l120a889ake5c524a537e68cb3@mail.gmail.com> Subject: Re: Tomcat Acceptor Thread goes into wait() to never come back - Tomcat 6.0 From: Hae Loong Chan To: Tomcat Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, If the threads are in the race condition, can it be any possibility the Tomcat will become responsive again - say if the current processing request thread is dropped due to request timeout and the browser is closed? On Tue, Mar 2, 2010 at 10:27 AM, Harshad Kamat wrote: > Hi, > > I believe I've found a race condition in Tomcat that causes the http port= to > be non-responsive. It exists in 6.0 and also in 5.5 (although the code ha= s > been refactored). > I could not find any reference to it in the Bug database or the mailing l= ist > archives. > > Consider a tomcat instance with maxThreads set to 2, i.e. you have 2 tomc= at > threads to service incoming requests. > The sequence of events is as follows: > 1. Thread 1 and Thread 2 are both servicing a request each. > 2. A third request comes in. > 3. In class JIOEndpoint.java, the acceptor thread calls methods > processSocket() which then calls getWorkerThread() which then calls > createWorkerThread(). > 4. createWorkerThread() returns null since both threads are busy processi= ng > the two requests. > 5. Here is the race condition in method getWorkerThread() in the code sho= wn > below > > protected Worker getWorkerThread(){ > ... > Worker workerThread =3D createWorkerThread(); > =A0 =A0 =A0 =A0while (workerThread =3D=3D null) { > =A0 =A0 =A0 =A0 =A0 =A0try { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0synchronized (workers) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0workers.wait(); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 =A0 =A0} > ... > } > > The acceptor thread executes the "while(workerThread =3D=3D null)" statem= ent and > is then switched out by the CPU. > The two threads executing the two requests complete and go into > Worker.await() waiting for the next job after executing method > recycleWorkerThread(). > The acceptor thread is switched back into CPU and executes the synchroniz= ed > block and goes into the wait(). > > At this point, there aren't any Worker threads out there processing reque= sts > and therefore there isn't any thread to wake up the acceptor thread. > The application is non-responsive after this. > > Thoughts? > > A simple solution would be to check if curThreadsBusy > 0 in the > synchronized block before going into wait() in method getWorkerThread(). > > Thanks, > Harshad > > > Stack Traces below: > > "bda19102143" id=3D1578 in WAITING on > lock=3Dorg.apache.tomcat.util.net.JIoEndpoint$Worker@13aa4ee3^M > =A0 =A0at java.lang.Object.wait(Native Method)^M > =A0 =A0at java.lang.Object.wait(Object.java:485)^M > =A0 =A0at > org.apache.tomcat.util.net.JIoEndpoint$Worker.await(JIoEndpoint.java:416)= ^M > =A0 =A0at > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:442)^M > =A0 =A0at java.lang.Thread.run(Thread.java:619)^M > > "http-8091-Acceptor-0" id=3D43 in WAITING on > lock=3Dorg.apache.tomcat.util.net.JIoEndpoint$WorkerStack@13bd7b6a^M > =A0 =A0at java.lang.Object.wait(Native Method)^M > =A0 =A0at java.lang.Object.wait(Object.java:485)^M > =A0 =A0at > org.apache.tomcat.util.net.JIoEndpoint.getWorkerThread(JIoEndpoint.java:7= 00)^M > =A0 =A0at > org.apache.tomcat.util.net.JIoEndpoint.processSocket(JIoEndpoint.java:731= )^M > =A0 =A0at > org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:313)= ^M > =A0 =A0at java.lang.Thread.run(Thread.java:619)^M > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org