From b78e4dacec2f0f02044c67577ce05be394e2ac61 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 14 May 2020 12:45:18 +0100 Subject: [PATCH] Work around file handle leak when Undertow is stopped There's a bug in Undertow that means it may leak a file handle is the server is stopped immediately after a response to an SSL request has been received. The stop processing races with Undertow's SSL support tidying things up after sending the response. When the stop processing wins, the tidying up fails with a NullPointerException that prevents an input stream from being closed. On Windows, the input stream remaining open prevents JUnit from being able to clean up its temporary directory. This commit uses Awaitility to wait for the file that's being served over SSL to be deleted before stopping the server. On Windows, this will delay the stop processing from beginning until after the tidy up that's performed after sending the response has been completed, hopefully eliminating the race condition that resulted in the input stream being left open. Fixes gh-21172 --- .../undertow/UndertowServletWebServerFactoryTests.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java index 199ae78392..493d279a41 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java @@ -36,6 +36,7 @@ import io.undertow.servlet.api.DeploymentInfo; import io.undertow.servlet.api.ServletContainer; import org.apache.jasper.servlet.JspServlet; import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -69,6 +70,13 @@ class UndertowServletWebServerFactoryTests extends AbstractServletWebServerFacto return new UndertowServletWebServerFactory(0); } + @AfterEach + void awaitClosureOfSslRelatedInputStreams() { + // https://issues.redhat.com/browse/UNDERTOW-1705 + File resource = new File(this.tempDir, "test.txt"); + Awaitility.await().atMost(Duration.ofSeconds(30)).until(() -> (!resource.isFile()) || resource.delete()); + } + @Test void errorPage404() throws Exception { AbstractServletWebServerFactory factory = getFactory();