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

Bug 361456

Summary: memory leak in SelectConnector onConnectionFailed
Product: [RT] Jetty Reporter: Eric Sybesma <erics>
Component: clientAssignee: Jan Bartel <janb>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: gregw, jetty-inbox
Version: unspecified   
Target Milestone: 7.5.x   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
A copy of my file that fixed the memory leak for me none

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