From dev-return-29245-apmail-mina-dev-archive=mina.apache.org@mina.apache.org Mon Dec 7 09:54:11 2015 Return-Path: X-Original-To: apmail-mina-dev-archive@www.apache.org Delivered-To: apmail-mina-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8E30618991 for ; Mon, 7 Dec 2015 09:54:11 +0000 (UTC) Received: (qmail 5142 invoked by uid 500); 7 Dec 2015 09:54:11 -0000 Delivered-To: apmail-mina-dev-archive@mina.apache.org Received: (qmail 5113 invoked by uid 500); 7 Dec 2015 09:54:11 -0000 Mailing-List: contact dev-help@mina.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mina.apache.org Delivered-To: mailing list dev@mina.apache.org Received: (qmail 5072 invoked by uid 99); 7 Dec 2015 09:54:11 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Dec 2015 09:54:11 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 074472C1F57 for ; Mon, 7 Dec 2015 09:54:11 +0000 (UTC) Date: Mon, 7 Dec 2015 09:54:11 +0000 (UTC) From: "Emmanuel Lecharny (JIRA)" To: dev@mina.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Reopened] (DIRMINA-1013) Threading model is supressed by ProtocolCodecFilter MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DIRMINA-1013?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Emmanuel Lecharny reopened DIRMINA-1013: ---------------------------------------- > Threading model is supressed by ProtocolCodecFilter > --------------------------------------------------- > > Key: DIRMINA-1013 > URL: https://issues.apache.org/jira/browse/DIRMINA-1013 > Project: MINA > Issue Type: Bug > Components: Core, Filter > Affects Versions: 2.0.9 > Environment: Windows 7 x32 > Java(TM) SE Runtime Environment (build 1.8.0_45-b14) > Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode, sharing) > Reporter: Marat Gainullin > Fix For: 2.0.10 > > > ProtocolCodecFilter.messageReceived uses a semaphore to protect the following critical section: > {code} > lock.acquire(); > // Call the decoder with the read bytes > decoder.decode(session, in, decoderOut); > // Finish decoding if no exception was thrown. > decoderOut.flush(nextFilter, session); > ... > {code} > in such fragment of code: > {code} > // Loop until we don't have anymore byte in the buffer, > // or until the decoder throws an unrecoverable exception or > // can't decoder a message, because there are not enough > // data in the buffer > while (in.hasRemaining()) { > int oldPos = in.position(); > try { > lock.acquire(); > // Call the decoder with the read bytes > decoder.decode(session, in, decoderOut); > // Finish decoding if no exception was thrown. > decoderOut.flush(nextFilter, session); > } catch (Exception e) { > ProtocolDecoderException pde; > if (e instanceof ProtocolDecoderException) { > pde = (ProtocolDecoderException) e; > } else { > pde = new ProtocolDecoderException(e); > } > if (pde.getHexdump() == null) { > // Generate a message hex dump > int curPos = in.position(); > in.position(oldPos); > pde.setHexdump(in.getHexDump()); > in.position(curPos); > } > // Fire the exceptionCaught event. > decoderOut.flush(nextFilter, session); > nextFilter.exceptionCaught(session, pde); > // Retry only if the type of the caught exception is > // recoverable and the buffer position has changed. > // We check buffer position additionally to prevent an > // infinite loop. > if (!(e instanceof RecoverableProtocolDecoderException) || (in.position() == oldPos)) { > break; > } > } finally { > lock.release(); > } > } > {code} > Using of semaphore > {code} > public class ProtocolCodecFilter extends IoFilterAdapter { > ... > private final Semaphore lock = new Semaphore(1, true); > {code} > pushs other threads to wait while one of them is decoding. In MINA 2.0.7 there was a synchronized block at the same place, but on other point - decoderOut, wich is created per ioSession. Thus it was a stripped lock. -- This message was sent by Atlassian JIRA (v6.3.4#6332)