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 unable to receive writeRequest message at sometimes) and fix the bug
Date Sat, 11 Jan 2020 18:22: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 unable to receive writeRequest message, the following code is bug and my
bug fix in ProtocolCodecFilter

{color:#ff0000}Note: 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 may lead to sent{color}
{color:#00875a}duplicated message ...
 // 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 some writeRequest is missed...{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 unable to receive writeRequest message, the following code is bug and my
bug fix in ProtocolCodecFilter

{color:#ff0000}Note: bug2 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 may lead to sent{color}
{color:#00875a}duplicated message ...
 // 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 some writeRequest is missed...{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 unable to receive writeRequest message at sometimes)
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.3
>            Reporter: li-libo
>            Priority: Major
>
> mina v2.1.1-v2.1.3 unable to receive writeRequest message, the following code is bug
and my bug fix in ProtocolCodecFilter
> {color:#ff0000}Note: 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 may lead
to sent{color} {color:#00875a}duplicated message ...
>  // 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 some writeRequest is missed...{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