Skip to content

Commit d93fa0d

Browse files
author
Alex Menkov
committed
8253940: com/sun/jdi/JdwpAttachTest.java failed with "RuntimeException: ERROR: LingeredApp.startApp was able to attach"
Reviewed-by: cjplummer, lmesnik
1 parent 104a262 commit d93fa0d

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

test/jdk/com/sun/jdi/JdwpAttachTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,10 +50,13 @@
5050
public class JdwpAttachTest {
5151

5252
// Set to true to perform testing of attach from wrong address (expected to fail).
53-
// It's off by default as it caused significant test time increase\
53+
// It's off by default as it caused significant test time increase
5454
// (tests <number_of_addresses> * <number_of_addresses> cases, each case fails by timeout).
5555
private static boolean testFailedAttach = false;
5656

57+
// A flag to exclude testcases which can cause intermittent CI failures.
58+
private static boolean testPotentiallyUnstableCases = false;
59+
5760
public static void main(String[] args) throws Exception {
5861
List<InetAddress> addresses = Utils.getAddressesWithSymbolicAndNumericScopes();
5962

@@ -81,11 +84,15 @@ public static void main(String[] args) throws Exception {
8184
}
8285
}
8386

84-
// by using "localhost" or empty hostname
85-
// we should be able to attach to both IPv4 and IPv6 addresses (127.0.0.1 & ::1)
87+
// By using "localhost" or empty hostname we should be able to attach
88+
// to both IPv4 and IPv6 addresses (127.0.0.1 & ::1).
89+
// By default test verifies only "preferred" family (IPv4 or IPv6).
90+
// Need to set testPotentiallyUnstableCases to true to perform full testing.
8691
InetAddress localAddresses[] = InetAddress.getAllByName("localhost");
8792
for (int i = 0; i < localAddresses.length; i++) {
88-
attachTest(localAddresses[i].getHostAddress(), "", true);
93+
if (testPotentiallyUnstableCases || addressIsSafeToConnectToLocalhost(localAddresses[i])) {
94+
attachTest(localAddresses[i].getHostAddress(), "", true);
95+
}
8996
}
9097
}
9198

@@ -168,6 +175,15 @@ private static void setConnectorArg(Map<String, Connector.Argument> args, String
168175
arg.setValue(value);
169176
}
170177

178+
// Attach to localhost tries to connect to both IPv4 and IPv6 loopback addresses.
179+
// But sometimes it causes interference with other processes which can listen
180+
// on the same port but different loopback address.
181+
// The method checks if the address is safe to test with current network config.
182+
private static boolean addressIsSafeToConnectToLocalhost(InetAddress addr) {
183+
boolean ipv6 = Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses"));
184+
return ipv6 == (addr instanceof Inet6Address);
185+
}
186+
171187
private static long startTime = System.currentTimeMillis();
172188

173189
private static void log(Object o) {

0 commit comments

Comments
 (0)