Fixed leaking file descriptors for file:// based URL connections on metadata reload.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 8 Sep 2004 20:03:11 +0000 (20:03 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 8 Sep 2004 20:03:11 +0000 (20:03 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1070 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/common/ResourceWatchdog.java

index 704b2f1..715be6f 100644 (file)
@@ -109,8 +109,9 @@ public abstract class ResourceWatchdog extends Thread {
 
        protected void checkAndRun() {
 
+               URLConnection connection = null;
                try {
-                       URLConnection connection = resource.getURL().openConnection();
+                       connection = resource.getURL().openConnection();
                        connection.connect();
 
                        log.debug("Checking for updates to resource (" + resource.getURL().toString() + ")");
@@ -153,6 +154,15 @@ public abstract class ResourceWatchdog extends Thread {
                                interrupted = true;
                                return;
                        }
+               } finally {
+                       //Silliness to avoid file descriptor leaks
+                       if (connection != null) {
+                               try {
+                                       connection.getInputStream().close();
+                               } catch (IOException e1) {
+                                       // ignore
+                               }
+                       }
                }
 
        }