From f5809420a5fecf0c1ca64ead7574724b1dc41138 Mon Sep 17 00:00:00 2001 From: Rsl1122 <24460436+Rsl1122@users.noreply.github.com> Date: Sat, 18 Jan 2020 11:27:05 +0200 Subject: [PATCH] Disconnect HTTP Connection after using IP2C Affects issues: - Possibly fixes #1296, #1291, #1292 --- .../gathering/geolocation/IP2CGeolocator.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/geolocation/IP2CGeolocator.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/geolocation/IP2CGeolocator.java index b054b7537..369a0c94e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/geolocation/IP2CGeolocator.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/geolocation/IP2CGeolocator.java @@ -72,15 +72,20 @@ public class IP2CGeolocator implements Geolocator { } public Optional readIPFromURL(String address) throws IOException { - HttpURLConnection connection = (HttpURLConnection) new URL("http://ip2c.org/" + address).openConnection(); - connection.setDefaultUseCaches(false); - connection.setUseCaches(false); - connection.connect(); - try ( - InputStream in = connection.getInputStream() - ) { - String answer = readAnswer(in); - return resolveIP(answer); + HttpURLConnection connection = null; + try { + connection = (HttpURLConnection) new URL("http://ip2c.org/" + address).openConnection(); + connection.setDefaultUseCaches(false); + connection.setUseCaches(false); + connection.connect(); + try ( + InputStream in = connection.getInputStream() + ) { + String answer = readAnswer(in); + return resolveIP(answer); + } + } finally { + if (connection != null) connection.disconnect(); } }