|
24 | 24 | import java.net.InetSocketAddress; |
25 | 25 | import java.net.ServerSocket; |
26 | 26 | import java.net.Socket; |
27 | | -import java.net.SocketException; |
28 | | -import java.net.UnknownHostException; |
29 | 27 | import java.nio.ByteBuffer; |
30 | 28 | import java.nio.channels.AsynchronousFileChannel; |
31 | 29 | import java.nio.channels.Channel; |
@@ -328,28 +326,12 @@ private void waitForServerStartup(StopWatch watch) throws IOException |
328 | 326 |
|
329 | 327 | private void verifyReady() throws SQLException |
330 | 328 | { |
331 | | - final InetAddress localhost; |
332 | | - try { |
333 | | - localhost = InetAddress.getByAddress(new byte[]{127, 0, 0, 1}); |
334 | | - } catch (final UnknownHostException e) { |
335 | | - throw new AssertionError("localhost unknown?", e); |
336 | | - } |
337 | | - final Socket sock = new Socket(); |
338 | | - try { |
| 329 | + final InetAddress localhost = InetAddress.getLoopbackAddress(); |
| 330 | + try (Socket sock = new Socket()) { |
339 | 331 | sock.setSoTimeout((int) Duration.ofMillis(500).toMillis()); |
340 | | - } catch (final SocketException e) { |
341 | | - throw new RuntimeException("error setting socket timeout", e); |
342 | | - } |
343 | | - try { |
344 | 332 | sock.connect(new InetSocketAddress(localhost, port), (int) Duration.ofMillis(500).toMillis()); |
345 | 333 | } catch (final IOException e) { |
346 | 334 | throw new SQLException("connect failed", e); |
347 | | - } finally { |
348 | | - try { |
349 | | - sock.close(); |
350 | | - } catch (final IOException e) { |
351 | | - LOG.trace("i/o exception closing test socket", e); |
352 | | - } |
353 | 335 | } |
354 | 336 | try (Connection c = getPostgresDatabase().getConnection() ; |
355 | 337 | Statement s = c.createStatement() ; |
|
0 commit comments