You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Eric Fitchett (JIRA)" <ji...@apache.org> on 2007/02/09 01:46:05 UTC

[jira] Updated: (DIRMINA-347) Server: StreamIoHandler does not close InputStream and OutputStream on sessionClosed()

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

Eric Fitchett updated DIRMINA-347:
----------------------------------

    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.

<code>
	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
			}
		}
	}
</code>

  was:
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
			}
		}
	}


> Server: StreamIoHandler does not close InputStream and OutputStream on sessionClosed()
> --------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-347
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-347
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.0.1
>         Environment: Ubuntu 6.06
>            Reporter: Eric Fitchett
>            Priority: Minor
>
> 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.
> <code>
> 	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
> 			}
> 		}
> 	}
> </code>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.