Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-574

ClassCastException when a message is written on a closed session.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Won't Fix
    • 1.0.10, 1.1.7, 2.0.0-M1
    • 2.0.8
    • Core
    • None

    Description

      Steps to reproduce:
      1) Connection is closed at the socket level.
      2) A user writes a message.
      3) the message is encoded by a ProtocolCodecFilter.
      4) MINA notices the closed socket and fires a sessionClosed event.
      5) After the sessionClosed event is fired, IoFilterChain.clear() is called.
      6) MINA tries to write the user write request, but the session is closed already - all write requests are discarded.
      7) Before MINA discards all write requests, MINA checks if the first item in the queue is an empty buffer, which means a special separator which is handled by ProtocolCodecFilter.
      8) If there's an empty buffer in the head of the queue, MINA fires a messageSent event with the empty buffer in the hope that ProtocolCodecFilter will catch it.
      9) However, the filter chain is empty and therefore IoHandler implementation gets ClassCastException.

      A possible workaround is just to ignore the exception, but we need to provide a correct fix for this issue.

      The following is the stack trace that explains this scenario:

      25151 [SocketAcceptorIoProcessor-0.4] WARN ServerPortSessionHandler -
      > [/127.0.0.1:57120 <http://127.0.0.1:57120>]
      > java.lang.ClassCastException:
      > org.apache.mina.filter.codec.ProtocolCodecFilter$MessageByteBuffer
      > incompatible with com.daishin.eai.adapter.socket.message.Por
      > tMessage
      > at
      > com.daishin.eai.adapter.socket.handler.ServerPortSessionHandler.messageSent(ServerPortSessionHandler.java:80)
      > at
      > org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageSent(AbstractIoFilterChain.java:579)
      > at
      > org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageSent(AbstractIoFilterChain.java:320)
      > at
      > org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:53)
      > at
      > org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageSent(AbstractIoFilterChain.java:653)
      > at
      > org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageSent(AbstractIoFilterChain.java:504)
      > at
      > org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageSent(AbstractIoFilterChain.java:320)
      > at
      > org.apache.mina.common.support.AbstractIoFilterChain.fireMessageSent(AbstractIoFilterChain.java:314)
      > at
      > org.apache.mina.transport.socket.nio.SocketIoProcessor.releaseWriteBuffers(SocketIoProcessor.java:359)
      > at
      > org.apache.mina.transport.socket.nio.SocketIoProcessor.doFlush(SocketIoProcessor.java:314)
      > at
      > org.apache.mina.transport.socket.nio.SocketIoProcessor.access$500(SocketIoProcessor.java:45)
      > at
      > org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:488)
      > at
      > org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
      > at
      > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
      > at
      > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
      > at java.lang.Thread.run(Thread.java:810)

      Attachments

        Activity

          People

            elecharny Emmanuel Lécharny
            trustin Trustin Lee
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: