Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

File descriptor leak after disconnects

843790Nov 19 2008 — edited Nov 20 2008
Hi there,

I'm having a problem with one of my applications. It's a high concurrency NIO (as in New IO packages, java.nio.*) based java server. The issue we're having is that if clients do not gracefully close the connection the server leaks file descriptors. We also have an excessive number of connections in CLOSE_WAIT state during this.

There was a known (and resolved) bug for this pre 1.5.07 : http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6215050

All fixed mentioned in this bug report do not solve this problem. The code to close the socket on the server end is as follows (yes i know it's overkill :) ) :
/* Close socket channel */
try { socketChannel().socket().getInputStream().close(); } catch (Exception e) {}
try { socketChannel().socket().getOutputStream().close(); } catch (Exception e) {}
try { socketChannel().socket().shutdownInput(); } catch (Exception e) {}
try { socketChannel().socket().shutdownOutput(); } catch (Exception e) {}
try { socketChannel().socket().close(); } catch (Exception e) {}
			
socketChannel().close();
This code is called for all connections that are closed, including the ones causing the leak. Is there anything I'm missing here? Information or suggestions would be greatly appreciated.

Regards,

Remon
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2008
Added on Nov 19 2008
7 comments
632 views