Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[misc] Leaking socket file descriptors when using unix domain sockets…
… when path doesn't exist
- Loading branch information
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // SPDX-License-Identifier: LGPL-2.1-or-later | ||
| // Copyright (c) 2012-2014 Monty Program Ab | ||
| // Copyright (c) 2015-2021 MariaDB Corporation Ab | ||
|
|
||
| package org.mariadb.jdbc.integration; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.sql.SQLNonTransientConnectionException; | ||
| import java.util.Properties; | ||
| import org.junit.jupiter.api.Assumptions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class UnixsocketTest extends Common { | ||
| private final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win"); | ||
|
|
||
| @Test | ||
| public void testConnectWithUnixSocketWhenDBNotUp() throws IOException { | ||
| Assumptions.assumeTrue(!isWindows); | ||
| String url = "jdbc:mariadb://localhost:3306"; | ||
| Properties properties = new Properties(); | ||
| properties.setProperty("localSocket", "/tmp/not_valid_socket"); | ||
| properties.setProperty("localSocketAddress", "localhost"); | ||
|
|
||
| java.sql.Driver driver = new org.mariadb.jdbc.Driver(); | ||
|
|
||
| Runtime rt = Runtime.getRuntime(); | ||
| // System.out.println("netstat-apnx | grep " + ProcessHandle.current().pid()); | ||
| String[] commands = {"/bin/sh", "-c", "netstat -apnx | grep " + ProcessHandle.current().pid()}; | ||
| Process proc = rt.exec(commands); | ||
|
|
||
| BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); | ||
| int initialLines = 0; | ||
| while (stdInput.readLine() != null) { | ||
| initialLines++; | ||
| } | ||
| proc.destroy(); | ||
|
|
||
| for (int i = 0; i < 10; i++) { | ||
| assertThrows( | ||
| SQLNonTransientConnectionException.class, | ||
| () -> { | ||
| driver.connect(url, properties); | ||
| }); | ||
| } | ||
| proc = rt.exec(commands); | ||
| stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); | ||
| int finalLines = 0; | ||
| while (stdInput.readLine() != null) { | ||
| finalLines++; | ||
| } | ||
| proc.destroy(); | ||
| assertEquals( | ||
| finalLines, | ||
| initialLines, | ||
| "Error Leaking socket file descriptors. initial :" | ||
| + initialLines | ||
| + " but ending with " | ||
| + finalLines); | ||
| } | ||
| } |