Skip to content

Commit 6eff659

Browse files
committed
UnixDomainProxyServer: Use random path
1 parent 7897698 commit 6eff659

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/extension/sync/UnixDomainProxyServer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.newsclub.net.unix.AFUNIXServerSocket;
3131
import org.newsclub.net.unix.AFUNIXSocket;
3232

33-
import java.io.File;
3433
import java.io.IOException;
3534
import java.io.InputStream;
3635
import java.io.OutputStream;
@@ -57,7 +56,7 @@ public final class UnixDomainProxyServer {
5756
public UnixDomainProxyServer(final int port) {
5857
this.port = port;
5958
this.executorService = Executors.newCachedThreadPool();
60-
this.socketPath = (new File("proxy.sock")).toPath();
59+
this.socketPath = createTempSocketPath();
6160
}
6261

6362
public void start() {
@@ -126,6 +125,16 @@ private void serveRequests(final AFUNIXServerSocket server) throws IOException {
126125
}
127126
}
128127

128+
private static Path createTempSocketPath() {
129+
try {
130+
final Path tempFile = Files.createTempFile("uds", ".sock");
131+
Files.deleteIfExists(tempFile);
132+
return tempFile;
133+
} catch (final IOException ex) {
134+
throw new RuntimeException(ex);
135+
}
136+
}
137+
129138
private Void pipe(final Socket inputSocket, final Socket outputSocket) {
130139
try (
131140
final InputStream in = inputSocket.getInputStream();

0 commit comments

Comments
 (0)