From dev-return-203565-archive-asf-public=cust-asf.ponee.io@tomcat.apache.org Wed Nov 20 13:26:01 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 8AF161804BB for ; Wed, 20 Nov 2019 14:26:01 +0100 (CET) Received: (qmail 92740 invoked by uid 500); 20 Nov 2019 13:25:46 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 92291 invoked by uid 99); 20 Nov 2019 13:25:45 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Nov 2019 13:25:45 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 75BAB8B693; Wed, 20 Nov 2019 13:25:45 +0000 (UTC) Date: Wed, 20 Nov 2019 13:25:48 +0000 To: "dev@tomcat.apache.org" Subject: [tomcat] 03/05: Handle case were Poller may return an entry per event MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: markt@apache.org In-Reply-To: <157425634526.5559.6264302273040181528@gitbox.apache.org> References: <157425634526.5559.6264302273040181528@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: tomcat X-Git-Refname: refs/heads/7.0.x X-Git-Reftype: branch X-Git-Rev: 4a8d1ff4f002ddf57883364fa7153e42f40393e6 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20191120132545.75BAB8B693@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git View the commit online: https://github.com/apache/tomcat/commit/4a8d1ff4f002ddf57883364fa7153e42f40393e6 commit 4a8d1ff4f002ddf57883364fa7153e42f40393e6 Author: Mark Thomas AuthorDate: Tue Nov 19 17:30:31 2019 +0000 Handle case were Poller may return an entry per event --- java/org/apache/tomcat/util/net/AprEndpoint.java | 45 +++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index dfca17b..a27ee22 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -1486,7 +1486,16 @@ public class AprEndpoint extends AbstractEndpoint { // It might not be worth bothering though. aprPoller = allocatePoller(pollerSize, pool, -1); - desc = new long[pollerSize * 2]; + /* + * x2 - One descriptor for the socket, one for the event(s). + * x2 - Some APR implementations return multiple events for the + * same socket as different entries. Each socket is registered + * for a maximum of two events (read and write) at any one + * time. + * + * Therefore size is poller size *4. + */ + desc = new long[pollerSize * 4]; connectionCount.set(0); addList = new SocketList(pollerSize); closeList = new SocketList(pollerSize); @@ -1838,6 +1847,7 @@ public class AprEndpoint extends AbstractEndpoint { int rv = Poll.poll(aprPoller, pollTime, desc, true); if (rv > 0) { + rv = mergeDescriptors(desc, rv); connectionCount.addAndGet(-rv); for (int n = 0; n < rv; n++) { if (getLog().isDebugEnabled()) { @@ -2033,6 +2043,39 @@ public class AprEndpoint extends AbstractEndpoint { this.notifyAll(); } } + + + private int mergeDescriptors(long[] desc, int startCount) { + /* + * https://bz.apache.org/bugzilla/show_bug.cgi?id=57653#c6 suggests + * this merging is only necessary on OSX and BSD. + * + * https://bz.apache.org/bugzilla/show_bug.cgi?id=56313 suggests the + * same, or a similar, issue is happening on Windows. + * Notes: Only the first startCount * 2 elements of the array + * are populated. + * The array is event, socket, event, socket etc. + */ + HashMap merged = new HashMap(startCount); + for (int n = 0; n < startCount; n++) { + Long old = merged.put(Long.valueOf(desc[2*n+1]), Long.valueOf(desc[2*n])); + if (old != null) { + // This was a replacement. Merge the old and new value + merged.put(Long.valueOf(desc[2*n+1]), + Long.valueOf(desc[2*n] | old.longValue())); + if (log.isDebugEnabled()) { + log.debug(sm.getString("endpoint.apr.pollMergeEvents", + Long.valueOf(desc[2*n+1]), Long.valueOf(desc[2*n]), old)); + } + } + } + int i = 0; + for (Map.Entry entry : merged.entrySet()) { + desc[i++] = entry.getValue().longValue(); + desc[i++] = entry.getKey().longValue(); + } + return merged.size(); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org