Skip to content
Permalink
Browse files
8253940: com/sun/jdi/JdwpAttachTest.java failed with "RuntimeExceptio…
…n: ERROR: LingeredApp.startApp was able to attach"

Reviewed-by: cjplummer, lmesnik
  • Loading branch information
Alex Menkov committed Mar 4, 2021
1 parent 104a262 commit d93fa0d6e348f00c62ab88321177a271406f9063
Showing 1 changed file with 21 additions and 5 deletions.
@@ -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 @@
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 static void main(String[] args) throws Exception {
}
}

// 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 @@ private static void setConnectorArg(Map<String, Connector.Argument> args, String
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) {

0 comments on commit d93fa0d

Please sign in to comment.