Greetings!

As stated in this seemingly unrelated ticket https://github.com/spring-projects/spring-boot/issues/38554 we are currently facing an issue when running multiple Spring boot tests one after another.

i took the liberty and created a reproducer for this case. The tests in the attached zip file work with spring boot 3.1.5 but fail on 3.2.0.

In my example I add a new http connector with a fixed port. When running each test on its own they work. But if they're executed in a row i.e. by a mvn verify the second tests fails on initialization stating that the configured connector failed to start.

Maven doesn't print the reason too clearly unfortunately but a little closer investigation inside a IDE reveals the java.net.BindException: Address already in use: bind exception.

SpringTestReproducer.zip

In this example also the "@DirtiesContext" doesn't help. It seems as if the Spring / ApplicationContext is cleaned up and the new server instance is going to boot but the old instance of the server hasn't shut down yet or isn't shutting down at all.

Thanks in advance!

Comment From: mhalbritter

For some reason, after this.webServer.stop(); has been called in org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle#stop, the process is still listening on port 8010:

ss -l -p -n | grep "pid=83209,"
tcp   LISTEN 0      100                                                      *:8010                   *:*    users:(("java",pid=83209,fd=58))

Interestingly, the connector for port 8080 has closed the listening socket.

In org.apache.tomcat.util.net.AbstractEndpoint#stop, for port 8010, the bindState is BOUND_ON_INIT, thus is skips the unbind in the stop method. This method is the one which closes the server socket. For port 8080, the state is BOUND_ON_START, thus closing the socket on stop.

Comment From: mhalbritter

In org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#customizeConnector, we have this:

// Don't bind to the socket prematurely if ApplicationContext is slow to start
connector.setProperty("bindOnInit", "false");

When adding this property to the 8010 connector, all tests pass.

Comment From: wilkinsona

That points towards https://github.com/spring-projects/spring-boot/commit/dbb24286ff2a9e2b159d33029f792cdf10397924 as being the cause. A BOUND_ON_INIT endpoint isn't unbound until destroy is called.

Comment From: mr-hamburg

Hi, without wanting to put pressure, this is absolutely not my intention, but just because I want to understand: so we wait until release 3.2.1 until this is fixed, is that correct? Best regards from Hamburg!

Comment From: mhalbritter

Yes. It will be released on 21th of December, see the calendar or the milestone.

Comment From: mr-hamburg

Thanks for the link, I'll save it for future reference. Best wishes and have a nice day!

Comment From: jamfor352

I'm still seeing this in 3.2.1 & 3.2.2.

Comment From: wilkinsona

@jamfor352 Without anything more to go on, we can only assume that you have a different problem as we believe that this one has been resolved. Please open a new issue that describes your situation in more detail and that provides a minimal example that reproduces it.

Comment From: soer84

Sorry for the lack of feedback - but just to let you know - we have been upgrading our repository to spring boot 3.2.1 and the tests were executing as expected. So this issue seems fixed for me.