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

Server: StreamIoHandler does not close InputStream and OutputStream on sessionClosed()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0.1
    • 1.0.2
    • Core
    • None
    • Ubuntu 6.06

    Description

      When reading from the InputStream provided by StreamIoHandler, the read can block indefinitely if the client closes the connection.
      This is caused by the StreamIoHandler not closing the provided streams in the sessionClosed() method. The InputStream remains open, waiting for more data. After many connections, there may be a large number of "zombie" threads that will never wake up.

      I will upload a patch to fix this problem. In the mean time, a workaround I am currently using follows. It keeps track of the InputStream for each session, and closes it when the session closes. This ensures the thread has a chance to terminate properly.

      protected final void processStreamIo(
      IoSession session,
      InputStream in,
      OutputStream out)

      { sessionStreams.put(session, in); // Process the streams in a separate thread new Worker(in, out).start(); }

      // Ensures session's InputStream gets closed, so the thread doesn't lock up
      private Map<IoSession,InputStream> sessionStreams = new HashMap<IoSession, InputStream>();
      @Override
      public void sessionClosed(IoSession session) throws Exception {
      super.sessionClosed(session);
      InputStream is = sessionStreams.get(session);
      if(null != is) {
      try

      { is.close(); }

      catch(IOException ioe)

      { // Ignore }

      }
      }

      Attachments

        1. StreamIoHandler_CloseStreams.diff
          0.9 kB
          Eric Fitchett

        Activity

          People

            trustin Trustin Lee
            eric_fitchett Eric Fitchett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: