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] [Created] (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 12:42:00 GMT
li-libo created DIRMINA-1121:

             Summary: 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

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}
 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);

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

{color:#FF0000}// bug 1:{color} {color:#00875a}the EncoderOut is not thread safe that may
lead to duplicated message sent...{color}
{color:#00875a} // ProtocolEncoderOutput encoderOut = getEncoderOut(session, nextFilter, writeRequest);{color}
 {color:#FF0000}// bug 1 fix:{color}
 ProtocolEncoderOutput encoderOut = new ProtocolEncoderOutputImpl(session, nextFilter, writeRequest);

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) {

// 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} // nextFilter.filterWrite(session, writeRequest);{color}
 {color:#FF0000}// bug 2 fix:{color}
 DefaultWriteRequest defaultWriteRequest = new DefaultWriteRequest(writeRequest.getOriginalMessage(),
 writeRequest.getFuture(), writeRequest.getDestination());
 nextFilter.filterWrite(session, defaultWriteRequest);
 } 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

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

View raw message