Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 81967 - URL connections are not closed properly -> TCP/IP stack hangs
Summary: URL connections are not closed properly -> TCP/IP stack hangs
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Update (deprecated - use Eclipse>Equinox>p2) (show other bugs)
Version: 3.0.1   Edit
Hardware: PC Windows XP
: P2 blocker with 1 vote (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Branko Tripkovic CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-28 12:18 EST by Udo Walker CLA
Modified: 2006-05-29 11:06 EDT (History)
1 user (show)

See Also:


Attachments
org.eclipse.ui.ide.patch.ConfigurationLogUpdateSection change (4.42 KB, patch)
2005-05-25 15:36 EDT, Branko Tripkovic CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Udo Walker CLA 2004-12-28 12:18:45 EST
When I want to update the Eclipse plugins from the main Eclipse server I can
select all plugins (e.g. EMF, VE, etc.). But after starting the download Eclipse
hangs after some time and also my whole system hangs (Windows XP SP2). The whole
TCP/IP stack hangs. It is the problem described here: 
http://www.microsoft.com/products/ee/transform.aspx?EvtSrc=Tcpip&EvtCat=None&EvtID=4226&EvtCatID=0&EvtType=Warning&EvtTypeID=2&EvtRptTime=1094593275&EvtTZBias=240&CoName=Microsoft%20Corporation&ProdName=Microsoft%c2%ae%20Windows%c2%ae%20Operating%20System&ProdVer=5.1.2600.2180&FileName=xpsp2res.dll&FileVer=5.1.2600.2180

To download properly the not found URL connections should be closed correct. I
found e.g. following code in one of the classes of the plugin
org.eclipse.update.core : 

org.eclipse.update.internal.core.HttpResponse.java:

public long getLastModified() {
  if (lastModified == 0) {
    if (connection == null)
      try {
        connection = url.openConnection();
      } catch (IOException e) {
      }
    if (connection != null)
       lastModified = connection.getLastModified();
  }
  return lastModified;
}


In the catch block the URL connection is not disconnected so this connection is
a "incomplete outbound TCP connection" (see on Microsoft page) and blocks the
processing of further connections.

There are probably many more such "incomplete" connections throughout the Update
plugin source code. These should be fixed for working under Windows XP.


("With TCP/IP stack hangs" I mean that I cannot open another connection while
Eclipse hangs (tries to connect), i.e. browser, email client, chat are not
working anymore. I have to kill the Eclipse process to contiune using the system!)
Comment 1 Dorian Birsan CLA 2004-12-28 13:48:21 EST
Udo, thanks for this complete report.
I will investigate it as soon as I get back from vacation.
Comment 2 Dorian Birsan CLA 2005-01-05 16:03:47 EST
I am still at SP1 level, so I can't properly test this.
How do you expect to handle the exception thrown?
If there is an exception during url.openConnection(), the connection object is 
still null, so I can't close it. Do you have any suggestions?
Comment 3 Udo Walker CLA 2005-01-10 09:32:04 EST
Hi Dorian,

the problem is not the case when the url could not be opened. The problem with
XP(SP2) are all the open connections. I.e. you should close all used connections.

Close an open connection like this:

if (this.connection instanceof HttpURLConnection) {
   ((HttpURLConnection) this.connection).disconnect();
}

Do this after you used the connection; same as if you close an inputstream after
usage.

If you have an error case where the connection is already open then close the
connection in any of the catch blocks or finalizers. 

In the catch block close the connection like this (I check also if the
connection is not null):

} catch (Exception ex) {
  if (this.connection != null) {
     if (this.connection instanceof HttpURLConnection) {
       ((HttpURLConnection) this.connection).disconnect();
     }
     this.connection = null;
  }
}

I saw the HttpURLConnection.disconnect() in your source only when the user
cancels the connection. It will never be closed in the "normal" case.

E.g. in the class HttpResponse:

public InputStream getInputStream(IProgressMonitor monitor)
  throws IOException, CoreException {
...
  connection = url.openConnection();
...
  this.in = connection.getInputStream();
  return in;
}

The code above opens the connection, gets the inputstream, returns the
inputstream, but never closes the connection, or?

Also the code i mentioned in the first bug submit should look like this:

public long getLastModified() {
  if (lastModified == 0) {
    if (connection == null)
      try {
        connection = url.openConnection();
      } catch (IOException e) {

----> if connection != null -> close it

      }
    if (connection != null)
      lastModified = connection.getLastModified();

----> close connection

    }
    return lastModified;
}

I hope this makes the solution clearer?
Comment 4 Dorian Birsan CLA 2005-01-10 11:10:02 EST
Thanks. I was only pointing out that connection was always null in the catch 
block, because if the url.openConnection fails, connection is never assigned, 
and it was null to start with. So the line with ----> below is redundant.

public long getLastModified() {
  if (lastModified == 0) {
    if (connection == null)
      try {
        connection = url.openConnection();
      } catch (IOException e) {

----> if connection != null -> close it

      }

I will take a look at the other usages. One potential drawback with closing 
connections after the use in a method will involve recreating them a couple of 
times. Having the connection cached in the HttpResponse avoids it. On the 
other hand, if not closed, it has the potential to create the problems you 
describe.
Comment 5 Dorian Birsan CLA 2005-04-01 12:05:33 EST
Udo, are you still seeing problems with the recent drivers (M5) ?
Comment 6 Rainer Schmitz CLA 2005-04-04 06:20:56 EDT
(In reply to comment #5)
> Udo, are you still seeing problems with the recent drivers (M5) ?

I just checked with 3.1M6, and the problem still exists. Checking for updates
from the eclipse site takes ages, then after a while eclipse displays an error
message which I can't read because the whole IDE is frozen.
However, this time other applications seemed not to be affected.
Comment 7 Dorian Birsan CLA 2005-04-04 09:31:18 EDT
Thanks. Did you run the update search in backround ?
Comment 8 Rainer Schmitz CLA 2005-04-04 09:37:45 EDT
(In reply to comment #7)
> Thanks. Did you run the update search in backround ?
No. When it was apparent the update would take a while I switched to firefox and
surfed the web, but I didn't use the "Run in background" dialog button.
Comment 9 Dejan Glozic CLA 2005-05-21 22:44:03 EDT
Branko, please investigate this problem and report any possible performance 
side-effects of the aggressive HTTp connection closing.
Comment 10 Branko Tripkovic CLA 2005-05-24 16:14:53 EDT
I could not reproduce the problem on our xp sp2 machine. I tried with current
nightly build, m6 and m7. I have also inspected and profiled the code and I
could not find where this problem might arise.
Comment 11 Branko Tripkovic CLA 2005-05-25 15:36:15 EDT
Created attachment 21773 [details]
org.eclipse.ui.ide.patch.ConfigurationLogUpdateSection change
Comment 12 Branko Tripkovic CLA 2005-05-25 15:53:30 EDT
Comment on attachment 21773 [details]
org.eclipse.ui.ide.patch.ConfigurationLogUpdateSection change

patch is for different bug
Comment 13 Udo Walker CLA 2005-06-03 09:26:42 EDT
Hi,

we still had this bug in E3.1M6. But in E3.1M7 the bug does not exist anymore.
Thanks!




Comment 14 Branko Tripkovic CLA 2005-06-03 10:35:34 EDT
FIXED, 
thanks Udo
Comment 15 Andreas Köhler CLA 2006-05-27 09:48:32 EDT
I see this (or a similar) bug with Eclipse 3.2 RC5 and RC6 running on WinXP SP2, Sun J2SE Version 1.5.0 (Build 1.5.0_07-b03). Both, Eclipse and the Java VM, are fresh installations. Unlike in the original description, only the TCP/IP stack, not the entire system seems to hang, causing existing connections to time out and preventing new connections from being established.

Steps to reproduce the bug:
1. Start Eclipse.
2. Download the Eclipse Modeling Framework from the Callisto discovery site
3. Wait for it to download, then click 'Install' in the Verification dialog ("Warning: You are about to install an unsigned feature.")

In the progress dialog, the progress bar goes up to about 20% ("Initializing..." in details) and a few seconds later you notice other connections dropping (e.g. IRC) and new connections cannot be established (IRC reconnection attempts, opening URLs in a webbrowser, etc.)
After waiting a bit more, an exception message comes up:
An exception occured while downloading feature from "http://download.eclipse.org/callisto/releases/features/org.eclipse.emf_2.2.0_v200605151820.jar"
After the exception message popped up, internet connections are possible again.
Comment 16 Rainer Schmitz CLA 2006-05-28 04:51:38 EDT
I can confirm Andreas observation on the recent Eclipse 3.2 release candidates. 
Comment 17 Branko Tripkovic CLA 2006-05-29 09:26:10 EDT
Andreas,
Can you please check bug 101575 and especially look at the comment 33. Your problem looks a lot like the problem described there
Comment 18 Andreas Köhler CLA 2006-05-29 10:32:06 EDT
(In reply to comment #17)
> Andreas,
> Can you please check bug 101575 and especially look at the comment 33. Your
> problem looks a lot like the problem described there
> 

Thanks for the hint, that workaround helped.
Comment 19 Branko Tripkovic CLA 2006-05-29 11:06:46 EDT
glad I could help