8253940: com/sun/jdi/JdwpAttachTest.java failed with "RuntimeException: ERROR: LingeredApp.startApp was able to attach"

Reviewed-by: cjplummer, lmesnik
This commit is contained in:
Alex Menkov 2021-03-04 00:39:28 +00:00
parent 104a26283a
commit d93fa0d6e3

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -50,10 +50,13 @@ import java.util.concurrent.Executors;
public class JdwpAttachTest {
// Set to true to perform testing of attach from wrong address (expected to fail).
// It's off by default as it caused significant test time increase\
// It's off by default as it caused significant test time increase
// (tests <number_of_addresses> * <number_of_addresses> cases, each case fails by timeout).
private static boolean testFailedAttach = false;
// A flag to exclude testcases which can cause intermittent CI failures.
private static boolean testPotentiallyUnstableCases = false;
public static void main(String[] args) throws Exception {
List<InetAddress> addresses = Utils.getAddressesWithSymbolicAndNumericScopes();
@ -81,11 +84,15 @@ public class JdwpAttachTest {
}
}
// by using "localhost" or empty hostname
// we should be able to attach to both IPv4 and IPv6 addresses (127.0.0.1 & ::1)
// By using "localhost" or empty hostname we should be able to attach
// to both IPv4 and IPv6 addresses (127.0.0.1 & ::1).
// By default test verifies only "preferred" family (IPv4 or IPv6).
// Need to set testPotentiallyUnstableCases to true to perform full testing.
InetAddress localAddresses[] = InetAddress.getAllByName("localhost");
for (int i = 0; i < localAddresses.length; i++) {
attachTest(localAddresses[i].getHostAddress(), "", true);
if (testPotentiallyUnstableCases || addressIsSafeToConnectToLocalhost(localAddresses[i])) {
attachTest(localAddresses[i].getHostAddress(), "", true);
}
}
}
@ -168,6 +175,15 @@ public class JdwpAttachTest {
arg.setValue(value);
}
// Attach to localhost tries to connect to both IPv4 and IPv6 loopback addresses.
// But sometimes it causes interference with other processes which can listen
// on the same port but different loopback address.
// The method checks if the address is safe to test with current network config.
private static boolean addressIsSafeToConnectToLocalhost(InetAddress addr) {
boolean ipv6 = Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses"));
return ipv6 == (addr instanceof Inet6Address);
}
private static long startTime = System.currentTimeMillis();
private static void log(Object o) {