Skip to content

Commit fedc464

Browse files
committed
Use same InetAddress for client and server in endpoint tests
Previously, the server was created with out an explicitly configured address. This lead to it using any local address which will prefer IPv6 (::0) if it's available. By contrast, the client was created with a base URL that specified localhost as the host. This meant the the client would prefer to connect to IPv4. Normally this wouldn't cause a problem as nothing would be listening on the port in the IPv4 stack so the client would then connect to the server being tested using the IPv6 stack. However, if another process was listening to the port in the IPv4 stack, the client would connect to the wrong server. This could lead to an unexpected 404 response (if the wrong server was an HTTP server) or a hang if it was not. There's a chance, although I think it's unlikely, that the problem described above is the cause of gh-10569. I think it's unlikely as the hang tracked by gh-10569 only occurs when running the WebFlux endpoint integration tests using Reactor Netty. If it was the problem described above, there's no reason that I can think of why we wouldn't have also seen it with the Web MVC endpoint integration tests.
1 parent fb7026b commit fedc464

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.actuate.endpoint.web;
1818

19+
import java.net.InetSocketAddress;
1920
import java.time.Duration;
2021
import java.util.Arrays;
2122
import java.util.Collections;
@@ -339,7 +340,9 @@ private void load(Class<?> configuration, String endpointPath,
339340
"test", Collections.singletonMap("endpointPath", endpointPath)));
340341
context.refresh();
341342
try {
342-
String url = "http://localhost:" + getPort(context) + endpointPath;
343+
InetSocketAddress address = new InetSocketAddress(getPort(context));
344+
String url = "http://" + address.getHostString() + ":" + address.getPort()
345+
+ endpointPath;
343346
consumer.accept(context, WebTestClient.bindToServer().baseUrl(url)
344347
.responseTimeout(TIMEOUT).build());
345348
}

0 commit comments

Comments
 (0)