mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-16 08:17:14 +00:00
Make sure the IpClient does not block forever when something wrong happens
This commit is contained in:
@@ -39,7 +39,8 @@ import java.util.Random;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@@ -144,18 +145,28 @@ public class IpcClient {
|
|||||||
.redirectError(discard)
|
.redirectError(discard)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
Future<int[]> future = ForkJoinPool.commonPool().submit(() -> {
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
||||||
|
Future<int[]> future = es.submit(() -> {
|
||||||
Socket s = ss.accept();
|
Socket s = ss.accept();
|
||||||
DataInputStream dis = new DataInputStream(s.getInputStream());
|
DataInputStream dis = new DataInputStream(s.getInputStream());
|
||||||
int rand2 = dis.readInt();
|
int rand2 = dis.readInt();
|
||||||
int port2 = dis.readInt();
|
int port2 = dis.readInt();
|
||||||
return new int[] { rand2, port2 };
|
return new int[] { rand2, port2 };
|
||||||
});
|
});
|
||||||
int[] res = future.get(5, TimeUnit.SECONDS);
|
int[] res;
|
||||||
|
try {
|
||||||
|
res = future.get(5, TimeUnit.SECONDS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
process.destroyForcibly();
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
es.shutdownNow();
|
||||||
|
ss.close();
|
||||||
|
}
|
||||||
if (rand != res[0]) {
|
if (rand != res[0]) {
|
||||||
process.destroyForcibly();
|
process.destroyForcibly();
|
||||||
|
throw new IllegalStateException("IpcServer did not respond with the correct random");
|
||||||
}
|
}
|
||||||
ss.close();
|
|
||||||
|
|
||||||
int port = res[1];
|
int port = res[1];
|
||||||
Socket socket = new Socket();
|
Socket socket = new Socket();
|
||||||
|
Reference in New Issue
Block a user