Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 358959

Summary: File descriptor leak with UnresolvedAddressException
Product: [RT] Jetty Reporter: Chris Dumoulin <chris>
Component: clientAssignee: Jan Bartel <janb>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jetty-inbox
Version: unspecified   
Target Milestone: 7.5.x   
Hardware: PC   
OS: Linux   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=358147
Whiteboard:
Attachments:
Description Flags
Test class that reproduces the problem none

Description Chris Dumoulin CLA 2011-09-26 14:56:04 EDT
Build Identifier: 7.2.0v20101020

A java.nio.channels.UnresolvedAddressException during a call to HttpClient.send() results in a file descriptor leak which eventually leads to "Too many open files" errors.

In a production application, I was seeing the following exceptions which were resulting in file descriptor leaks:

java.nio.channels.UnresolvedAddressException 
        at sun.nio.ch.Net.checkAddress(Net.java:30) 
        at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:480) 
        at org.eclipse.jetty.client.SelectConnector.startConnection(SelectConnector.java:143) 
        at org.eclipse.jetty.client.HttpDestination.startNewConnection(HttpDestination.java:254) 
        at org.eclipse.jetty.client.HttpDestination.doSend(HttpDestination.java:548) 
        at org.eclipse.jetty.client.HttpDestination.send(HttpDestination.java:489) 
        at org.eclipse.jetty.client.HttpClient.send(HttpClient.java:148)

I created a test application that I'll attach which reproduces the problem. While the test application is running use "lsof -p <pid>|wc -l" to see the number of open files for the process. The number of open files will grow with each send() attempt until eventually you get "Too many open files" errors.


Reproducible: Always

Steps to Reproduce:
1. Run the attached UnresolvedAddressTest
2. Use lsof to see the open files for the process
3. Notice that the number of open files increases with each loop iteration
Comment 1 Chris Dumoulin CLA 2011-09-26 14:57:00 EDT
Created attachment 204035 [details]
Test class that reproduces the problem
Comment 2 Jan Bartel CLA 2011-09-28 01:01:36 EDT
Fixed. Also changes the fix for bug 358147 to be a single try/catch block for IOException and close the channel.
Comment 3 Chris Dumoulin CLA 2011-09-28 08:39:22 EDT
(In reply to comment #2)
> Fixed. Also changes the fix for bug 358147 to be a single try/catch block for
> IOException and close the channel.

I don't think UnresolvedAddressException is an IOException, so with the latest change it will no longer be caught.
Comment 4 Jan Bartel CLA 2011-10-09 21:55:37 EDT
This is a duplicate of https://bugs.eclipse.org/bugs/show_bug.cgi?id=358147
Comment 5 Jan Bartel CLA 2011-10-09 22:11:19 EDT
I misread the inheritance hierarchy for the UnresolvedAddressException. Indeed it is not an IOException. 

I've checked in a fix for that, and will be released for jetty-7.5.3.