mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "li-libo (Jira)" <j...@apache.org>
Subject [jira] [Updated] (DIRMINA-1121) Find the bug(Mina v2.1.1 -v2.1.3 are unable to receive writeRequest message in concurrent access) and fix the bug
Date Sat, 11 Jan 2020 19:35:00 GMT

     [ https://issues.apache.org/jira/browse/DIRMINA-1121?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

li-libo updated DIRMINA-1121:
-----------------------------
    Description: 
Mina v2.1.1-v2.1.3 are unable to receive writeRequest message in concurrent access, the following
code is bug and my bug fix in ProtocolCodecFilter # filterWrite method

{color:#ff0000}Note: The bug 2 is major bug!{color}

/**
 * {@inheritDoc}*/
 @Override
 public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
throws Exception
 { Object message = writeRequest.getMessage(); // Bypass the encoding if the message is contained
in a IoBuffer, // as it has already been encoded before if ((message instanceof IoBuffer)
|| (message instanceof FileRegion))
{ nextFilter.filterWrite(session, writeRequest); return; }

// Get the encoder in the session
 ProtocolEncoder encoder = factory.getEncoder(session);

{color:#ff0000}// bug 1:{color} {color:#00875a}The encoderOut is public that can cause {color}{color:#00875a}duplicated
message to sent.
 // ProtocolEncoderOutput encoderOut = getEncoderOut(session, nextFilter, writeRequest);{color}

{color:#ff0000}// bug 1 fix:{color}
 {color:#de350b}ProtocolEncoderOutput encoderOut = new ProtocolEncoderOutputImpl(session,
nextFilter, writeRequest);{color}

if (encoder == null)

{ throw new ProtocolEncoderException("The encoder is null for the session " + session); }

try {
 // Now we can try to encode the response
 encoder.encode(session, message, encoderOut);

// Send it directly
 Queue<Object> bufferQueue = ((AbstractProtocolEncoderOutput) encoderOut).getMessageQueue();

// Write all the encoded messages now
 while (!bufferQueue.isEmpty()) {
 Object encodedMessage = bufferQueue.poll();

if (encodedMessage == null)

{ break; }

// Flush only when the buffer has remaining.
 if (!(encodedMessage instanceof IoBuffer) || ((IoBuffer) encodedMessage).hasRemaining())
{
 {color:#ff0000}// major bug 2:{color} {color:#00875a}The same writeRequest resets when the
code enters while loop sencondly,{color} 
 {color:#00875a}// it will lead to the current writeRequest's messageĀ  is lost.{color}

{color:#00875a}// writeRequest.setMessage(encodedMessage);{color}
 {color:#00875a} // nextFilter.filterWrite(session, writeRequest);{color}
 {color:#ff0000}// bug 2 fix:{color}
 {color:#de350b}DefaultWriteRequest defaultWriteRequest = new DefaultWriteRequest(writeRequest.getOriginalMessage(),{color}
 {color:#de350b} writeRequest.getFuture(), writeRequest.getDestination());{color}
 {color:#de350b} defaultWriteRequest.setMessage(encodedMessage);{color}
 {color:#de350b} nextFilter.filterWrite(session, defaultWriteRequest);{color}
 }
 }
 } catch (Exception e) {
 ProtocolEncoderException pee;

// Generate the correct exception
 if (e instanceof ProtocolEncoderException)

{ pee = (ProtocolEncoderException) e; }

else

{ pee = new ProtocolEncoderException(e); }

throw pee;
 }
 }

  was:
Mina v2.1.1-v2.1.3 are unable to receive writeRequest message in concurrent access, the following
code is bug and my bug fix in ProtocolCodecFilter # filterWrite method

{color:#ff0000}Note: The bug 2 is major bug!{color}

/**
 * {@inheritDoc}*/
 @Override
 public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
throws Exception
 { Object message = writeRequest.getMessage(); // Bypass the encoding if the message is contained
in a IoBuffer, // as it has already been encoded before if ((message instanceof IoBuffer)
|| (message instanceof FileRegion))
{ nextFilter.filterWrite(session, writeRequest); return; }

// Get the encoder in the session
 ProtocolEncoder encoder = factory.getEncoder(session);

{color:#ff0000}// bug 1:{color} {color:#00875a}The encoderOut is public that can cause {color}{color:#00875a}duplicated
message to sent.
 // ProtocolEncoderOutput encoderOut = getEncoderOut(session, nextFilter, writeRequest);{color}

{color:#ff0000}// bug 1 fix:{color}
 {color:#de350b}ProtocolEncoderOutput encoderOut = new ProtocolEncoderOutputImpl(session,
nextFilter, writeRequest);{color}

if (encoder == null)

{ throw new ProtocolEncoderException("The encoder is null for the session " + session); }

try {
 // Now we can try to encode the response
 encoder.encode(session, message, encoderOut);

// Send it directly
 Queue<Object> bufferQueue = ((AbstractProtocolEncoderOutput) encoderOut).getMessageQueue();

// Write all the encoded messages now
 while (!bufferQueue.isEmpty()) {
 Object encodedMessage = bufferQueue.poll();

if (encodedMessage == null)

{ break; }

// Flush only when the buffer has remaining.
 if (!(encodedMessage instanceof IoBuffer) || ((IoBuffer) encodedMessage).hasRemaining())
{
 {color:#ff0000}// major bug 2:{color} {color:#00875a}The writeRequest resets when the code
enters while loop sencondly,{color} 
 {color:#00875a}// it will lead to the current writeRequest's messageĀ  is lost.{color}

{color:#00875a}// writeRequest.setMessage(encodedMessage);{color}
 {color:#00875a} // nextFilter.filterWrite(session, writeRequest);{color}
 {color:#ff0000}// bug 2 fix:{color}
 {color:#de350b}DefaultWriteRequest defaultWriteRequest = new DefaultWriteRequest(writeRequest.getOriginalMessage(),{color}
 {color:#de350b} writeRequest.getFuture(), writeRequest.getDestination());{color}
 {color:#de350b} defaultWriteRequest.setMessage(encodedMessage);{color}
 {color:#de350b} nextFilter.filterWrite(session, defaultWriteRequest);{color}
 }
 }
 } catch (Exception e) {
 ProtocolEncoderException pee;

// Generate the correct exception
 if (e instanceof ProtocolEncoderException)

{ pee = (ProtocolEncoderException) e; }

else

{ pee = new ProtocolEncoderException(e); }

throw pee;
 }
 }


> Find the bug(Mina v2.1.1 -v2.1.3 are unable to receive writeRequest message in concurrent
access) and fix the bug
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-1121
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-1121
>             Project: MINA
>          Issue Type: Bug
>          Components: Filter
>    Affects Versions: 2.1.1, 2.1.2, 2.1.3
>            Reporter: li-libo
>            Priority: Major
>
> Mina v2.1.1-v2.1.3 are unable to receive writeRequest message in concurrent access, the
following code is bug and my bug fix in ProtocolCodecFilter # filterWrite method
> {color:#ff0000}Note: The bug 2 is major bug!{color}
> /**
>  * {@inheritDoc}*/
>  @Override
>  public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
throws Exception
>  { Object message = writeRequest.getMessage(); // Bypass the encoding if the message
is contained in a IoBuffer, // as it has already been encoded before if ((message instanceof
IoBuffer) || (message instanceof FileRegion))
> { nextFilter.filterWrite(session, writeRequest); return; }
> // Get the encoder in the session
>  ProtocolEncoder encoder = factory.getEncoder(session);
> {color:#ff0000}// bug 1:{color} {color:#00875a}The encoderOut is public that can cause
{color}{color:#00875a}duplicated message to sent.
>  // ProtocolEncoderOutput encoderOut = getEncoderOut(session, nextFilter, writeRequest);{color}
> {color:#ff0000}// bug 1 fix:{color}
>  {color:#de350b}ProtocolEncoderOutput encoderOut = new ProtocolEncoderOutputImpl(session,
nextFilter, writeRequest);{color}
> if (encoder == null)
> { throw new ProtocolEncoderException("The encoder is null for the session " + session);
}
> try {
>  // Now we can try to encode the response
>  encoder.encode(session, message, encoderOut);
> // Send it directly
>  Queue<Object> bufferQueue = ((AbstractProtocolEncoderOutput) encoderOut).getMessageQueue();
> // Write all the encoded messages now
>  while (!bufferQueue.isEmpty()) {
>  Object encodedMessage = bufferQueue.poll();
> if (encodedMessage == null)
> { break; }
> // Flush only when the buffer has remaining.
>  if (!(encodedMessage instanceof IoBuffer) || ((IoBuffer) encodedMessage).hasRemaining())
{
>  {color:#ff0000}// major bug 2:{color} {color:#00875a}The same writeRequest resets when
the code enters while loop sencondly,{color} 
>  {color:#00875a}// it will lead to the current writeRequest's messageĀ  is lost.{color}
> {color:#00875a}// writeRequest.setMessage(encodedMessage);{color}
>  {color:#00875a} // nextFilter.filterWrite(session, writeRequest);{color}
>  {color:#ff0000}// bug 2 fix:{color}
>  {color:#de350b}DefaultWriteRequest defaultWriteRequest = new DefaultWriteRequest(writeRequest.getOriginalMessage(),{color}
>  {color:#de350b} writeRequest.getFuture(), writeRequest.getDestination());{color}
>  {color:#de350b} defaultWriteRequest.setMessage(encodedMessage);{color}
>  {color:#de350b} nextFilter.filterWrite(session, defaultWriteRequest);{color}
>  }
>  }
>  } catch (Exception e) {
>  ProtocolEncoderException pee;
> // Generate the correct exception
>  if (e instanceof ProtocolEncoderException)
> { pee = (ProtocolEncoderException) e; }
> else
> { pee = new ProtocolEncoderException(e); }
> throw pee;
>  }
>  }



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org


Mime
View raw message