Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 361456 - memory leak in SelectConnector onConnectionFailed
Summary: memory leak in SelectConnector onConnectionFailed
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: client (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 critical (vote)
Target Milestone: 7.5.x   Edit
Assignee: Jan Bartel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-19 15:02 EDT by Eric Sybesma CLA
Modified: 2011-10-20 18:20 EDT (History)
2 users (show)

See Also:


Attachments
A copy of my file that fixed the memory leak for me (15.77 KB, text/plain)
2011-10-19 15:03 EDT, Eric Sybesma CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Sybesma CLA 2011-10-19 15:02:10 EDT
Build Identifier: jetty-client-7.4.5.v20110725.jar

Package org.eclipse.jetty.client

The Jetty HttpClient, when connectorType is set to CONNECTOR_SELECT_CHANNEL creates a connector of type SelectConnector

SelectConnector has a HashMap of ConnectTimeout tasks for connections that time out.  This hash map is called _connectingChannels.

The Eclipse Memory Analyzer illustrates that _connectingChannels is holding onto Timeout Tasks that in turn reference exchanges, sockets, and destination classes.

I went to an eclipse mirror web site and grabbed the code for jetty.client. SelectConnector.java.

https://oss.sonatype.org/content/groups/jetty/org/eclipse/jetty/jetty-client/7.4.5.v20110725/

            if (!_httpClient.isConnectBlocking())
            {
                channel.configureBlocking( false );
                channel.connect(address.toSocketAddress());
                _selectorManager.register( channel, destination );
                ConnectTimeout connectTimeout = new ConnectTimeout(channel, destination);
                _httpClient.schedule(connectTimeout,_httpClient.getConnectTimeout());

                _connectingChannels.put(channel, connectTimeout);
            

There is only one method which removes the entry and that only happens on a successful connection.

        protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException
        {
            // We're connected, cancel the connect timeout
            Timeout.Task connectTimeout = _connectingChannels.remove(channel);
            if (connectTimeout != null)
                connectTimeout.cancel()

On exceptions or actual timeouts, I do not believe there is code to remove the hashmap entry.

Thus, I patched the source file, and fixed my symptoms. Patch will be attached.

Reproducible: Always

Steps to Reproduce:
1.  use select connector in non-blocking mode
2.  attempt to send asynchronous request to a non-responding address
3.  use eclipse memory analyzer to illustrate that _connectingChannels has a memory leak.
Comment 1 Eric Sybesma CLA 2011-10-19 15:03:52 EDT
Created attachment 205561 [details]
A copy of my file that fixed the memory leak for me
Comment 2 Greg Wilkins CLA 2011-10-20 17:58:50 EDT
I like issues with patches!
Comment 3 Greg Wilkins CLA 2011-10-20 18:20:56 EDT
fixed for 7.5.4