File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/web/embedded/undertow
test/java/org/springframework/boot/web/embedded/undertow Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 2222import io .undertow .server .HttpHandler ;
2323import io .undertow .server .HttpServerExchange ;
2424import io .undertow .servlet .api .DeploymentManager ;
25+ import io .undertow .servlet .api .DeploymentManager .State ;
2526import jakarta .servlet .ServletException ;
2627
2728import org .springframework .util .Assert ;
@@ -76,12 +77,14 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
7677
7778 @ Override
7879 public void close () throws IOException {
79- try {
80- this .deploymentManager .stop ();
81- this .deploymentManager .undeploy ();
82- }
83- catch (ServletException ex ) {
84- throw new RuntimeException (ex );
80+ if (this .deploymentManager .getState () != State .UNDEPLOYED ) {
81+ try {
82+ this .deploymentManager .stop ();
83+ this .deploymentManager .undeploy ();
84+ }
85+ catch (ServletException ex ) {
86+ throw new RuntimeException (ex );
87+ }
8588 }
8689 }
8790
Original file line number Diff line number Diff line change 5454import org .springframework .boot .web .server .GracefulShutdownResult ;
5555import org .springframework .boot .web .server .PortInUseException ;
5656import org .springframework .boot .web .server .Shutdown ;
57+ import org .springframework .boot .web .server .WebServer ;
5758import org .springframework .boot .web .servlet .ServletRegistrationBean ;
5859import org .springframework .boot .web .servlet .server .AbstractServletWebServerFactory ;
5960import org .springframework .boot .web .servlet .server .AbstractServletWebServerFactoryTests ;
6465import static org .assertj .core .api .Assertions .assertThat ;
6566import static org .assertj .core .api .Assertions .assertThatIOException ;
6667import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
68+ import static org .assertj .core .api .Assertions .assertThatNoException ;
6769import static org .hamcrest .Matchers .is ;
6870import static org .mockito .ArgumentMatchers .any ;
6971import static org .mockito .Mockito .inOrder ;
@@ -320,6 +322,16 @@ void sslRestrictedProtocolsRSATLS11Failure() {
320322 .isInstanceOfAny (SSLException .class , SocketException .class );
321323 }
322324
325+ @ Test
326+ void multipleCallsToDestroyAreTolerated () {
327+ AbstractServletWebServerFactory factory = getFactory ();
328+ factory .setPort (0 );
329+ WebServer webServer = factory .getWebServer ();
330+ webServer .start ();
331+ webServer .destroy ();
332+ assertThatNoException ().isThrownBy (webServer ::destroy );
333+ }
334+
323335 @ Override
324336 protected JspServlet getJspServlet () {
325337 return null ; // Undertow does not support JSPs
You can’t perform that action at this time.
0 commit comments