From dev-return-58794-archive-asf-public=cust-asf.ponee.io@thrift.apache.org Sun Jun 14 01:07:02 2020 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 5FF7518064C for ; Sun, 14 Jun 2020 03:07:02 +0200 (CEST) Received: (qmail 6452 invoked by uid 500); 14 Jun 2020 01:07:01 -0000 Mailing-List: contact dev-help@thrift.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@thrift.apache.org Delivered-To: mailing list dev@thrift.apache.org Received: (qmail 6436 invoked by uid 99); 14 Jun 2020 01:07:01 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Jun 2020 01:07:01 +0000 Received: from jira-he-de.apache.org (static.172.67.40.188.clients.your-server.de [188.40.67.172]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 8DD0340F9D for ; Sun, 14 Jun 2020 01:07:00 +0000 (UTC) Received: from jira-he-de.apache.org (localhost.localdomain [127.0.0.1]) by jira-he-de.apache.org (ASF Mail Server at jira-he-de.apache.org) with ESMTP id 0F5127802F0 for ; Sun, 14 Jun 2020 01:07:00 +0000 (UTC) Date: Sun, 14 Jun 2020 01:07:00 +0000 (UTC) From: "zengji (Jira)" To: dev@thrift.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (THRIFT-5230) Fix connection leak and CancelledKeyException when handling Epoll bug MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/THRIFT-5230?page=3Dcom.atlassi= an.jira.plugin.system.issuetabpanels:all-tabpanel ] zengji updated THRIFT-5230: --------------------------- Description:=20 1. When Epoll bug occurs, the TThreadedSelectorServer.rebuildSelector rebui= lds only the channel has events, the idle connection was ignored and caused= connection leak =C2=A0 {code:java} for (SelectionKey key : oldSelector.selectedKeys()) { if (!key.isValid() && key.readyOps() =3D=3D 0) continue; SelectableChannel channel =3D key.channel(); Object attachment =3D key.attachment(); try { if (attachment =3D=3D null) { channel.register(newSelector, key.readyOps()); } else { channel.register(newSelector, key.readyOps(), attachment); } } catch (ClosedChannelException e) { LOGGER.error("Register new selector key error.", e); } } selector =3D newSelector; try { oldSelector.close(); } catch (IOException e) { LOGGER.error("Close old selector error.", e); } {code} 2. When re-register the channel to new selector, the interested ops should = same as before, not only the readyOps =C2=A0 3. In the same code block, the channel will be registered to a new selector= and the previous selector will be closed, but the FrameBuffer is still hol= ding the previous selector causing the=C2=A0FrameBuffer in a wrong state. W= hen the FrameBuffer is trying to processing the channel, it may occur a=C2= =A0CancelledKeyException.This issue (CancelledKeyException) has been report= ed before:https://issues.apache.org/jira/browse/THRIFT-4847 was: 1. When Epoll bug occurs, the TThreadedSelectorServer.rebuildSelector rebui= lds only the channel has events, the idle connection was ignored and caused= connection leak =C2=A0 {code:java} for (SelectionKey key : oldSelector.selectedKeys()) { if (!key.isValid() && key.readyOps() =3D=3D 0) continue; SelectableChannel channel =3D key.channel(); Object attachment =3D key.attachment(); try { if (attachment =3D=3D null) { channel.register(newSelector, key.readyOps()); } else { channel.register(newSelector, key.readyOps(), attachment); } } catch (ClosedChannelException e) { LOGGER.error("Register new selector key error.", e); } } selector =3D newSelector; try { oldSelector.close(); } catch (IOException e) { LOGGER.error("Close old selector error.", e); } {code} 2. When re-register the channel to new selector, the interested ops should = same as before, not only the readyOps =C2=A0 3. In the same code block, the channel will be registered to a new selector= and the previous selector will be closed, but the FrameBuffer is still hol= ding the previous selector causing the=C2=A0FrameBuffer in a wrong state. W= hen the FrameBuffer is trying to processing the channel, it may occur a=C2= =A0CancelledKeyException. This issue has been reported before: https://issues.apache.org/jira/browse/THRIFT-4847 > Fix connection leak and CancelledKeyException when handling Epoll bug > --------------------------------------------------------------------- > > Key: THRIFT-5230 > URL: https://issues.apache.org/jira/browse/THRIFT-5230 > Project: Thrift > Issue Type: Bug > Components: Java - Library > Affects Versions: 0.13.0 > Environment: java version "1.8.0_161" > Reporter: zengji > Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > > 1. When Epoll bug occurs, the TThreadedSelectorServer.rebuildSelector reb= uilds only the channel has events, the idle connection was ignored and caus= ed connection leak > =C2=A0 > {code:java} > for (SelectionKey key : oldSelector.selectedKeys()) { > if (!key.isValid() && key.readyOps() =3D=3D 0) > continue; > SelectableChannel channel =3D key.channel(); > Object attachment =3D key.attachment(); > try { > if (attachment =3D=3D null) { > channel.register(newSelector, key.readyOps()); > } else { > channel.register(newSelector, key.readyOps(), attachment); > } > } catch (ClosedChannelException e) { > LOGGER.error("Register new selector key error.", e); > } > } > selector =3D newSelector; > try { > oldSelector.close(); > } catch (IOException e) { > LOGGER.error("Close old selector error.", e); > } > {code} > 2. When re-register the channel to new selector, the interested ops shoul= d same as before, not only the readyOps > =C2=A0 > 3. In the same code block, the channel will be registered to a new select= or and the previous selector will be closed, but the FrameBuffer is still h= olding the previous selector causing the=C2=A0FrameBuffer in a wrong state.= When the FrameBuffer is trying to processing the channel, it may occur a= =C2=A0CancelledKeyException.This issue (CancelledKeyException) has been rep= orted before:https://issues.apache.org/jira/browse/THRIFT-4847 -- This message was sent by Atlassian Jira (v8.3.4#803005)