Ticket #16540: 0001-Prevent-blocking-after-an-exception.patch

File 0001-Prevent-blocking-after-an-exception.patch, 3.7 KB (added by leeroy, 4 years ago)
  • src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java

    From 5da3ede1e613b453c8b3c32aecf3b75f72d669cc Mon Sep 17 00:00:00 2001
    From: leeroy <ter.one.leeboi@hush.com>
    Date: Fri, 10 Jul 2015 20:26:56 -0400
    Subject: [PATCH 1/1] Prevent blocking after an exception.
    
    ---
     src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java | 8 ++++++--
     src/org/torproject/descriptor/impl/DirectoryDownloader.java     | 5 +++--
     2 files changed, 9 insertions(+), 4 deletions(-)
    
    diff --git a/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java b/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
    index e5f2f9c..222c4e0 100644
    a b public class DescriptorCollectorImpl implements DescriptorCollector { 
    112112
    113113  String fetchRemoteDirectory(String url) {
    114114    StringBuilder sb = new StringBuilder();
     115    HttpURLConnection huc = null;
    115116    try {
    116117      URL u = new URL(url);
    117       HttpURLConnection huc = (HttpURLConnection) u.openConnection();
     118      huc = (HttpURLConnection) u.openConnection();
    118119      huc.setRequestMethod("GET");
    119120      huc.connect();
    120121      int responseCode = huc.getResponseCode();
    public class DescriptorCollectorImpl implements DescriptorCollector { 
    129130      }
    130131    } catch (IOException e) {
    131132      e.printStackTrace();
     133      if (huc != null) huc.disconnect();
    132134      return "";
    133135    }
    134136    return sb.toString();
    public class DescriptorCollectorImpl implements DescriptorCollector { 
    184186
    185187  void fetchRemoteFile(String url, File destinationFile,
    186188      long lastModifiedMillis) {
     189    HttpURLConnection huc = null;
    187190    try {
    188191      File destinationDirectory = destinationFile.getParentFile();
    189192      destinationDirectory.mkdirs();
    public class DescriptorCollectorImpl implements DescriptorCollector { 
    191194          + destinationFile.getName());
    192195      FileOutputStream fos = new FileOutputStream(tempDestinationFile);
    193196      URL u = new URL(url);
    194       HttpURLConnection huc = (HttpURLConnection) u.openConnection();
     197      huc = (HttpURLConnection) u.openConnection();
    195198      huc.setRequestMethod("GET");
    196199      if (!url.endsWith(".xz")) {
    197200        huc.addRequestProperty("Accept-Encoding", "gzip");
    public class DescriptorCollectorImpl implements DescriptorCollector { 
    219222      }
    220223    } catch (IOException e) {
    221224      e.printStackTrace();
     225      if (huc != null) huc.disconnect();
    222226    }
    223227  }
    224228
  • src/org/torproject/descriptor/impl/DirectoryDownloader.java

    diff --git a/src/org/torproject/descriptor/impl/DirectoryDownloader.java b/src/org/torproject/descriptor/impl/DirectoryDownloader.java
    index f10fc83..fab4b61 100644
    a b public class DirectoryDownloader implements Runnable { 
    5858        String url = "http://" + this.ipPort
    5959            + request.getRequestedResource();
    6060        request.setRequestStart(System.currentTimeMillis());
     61        HttpURLConnection huc = null;
    6162        try {
    6263          URL u = new URL(url);
    63           HttpURLConnection huc =
    64               (HttpURLConnection) u.openConnection();
     64          huc = (HttpURLConnection) u.openConnection();
    6565          huc.setConnectTimeout((int) this.connectTimeout);
    6666          huc.setReadTimeout((int) this.readTimeout);
    6767          huc.setRequestMethod("GET");
    public class DirectoryDownloader implements Runnable { 
    8686          }
    8787        } catch (Exception e) {
    8888          request.setException(e);
     89          if (huc != null) huc.disconnect();
    8990          /* Stop downloading from this directory if there are any
    9091           * problems, e.g., refused connections. */
    9192          keepRunning = false;