Skip to content

Commit b78e4da

Browse files
committed
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 spring-projectsgh-21172
1 parent 5eabb04 commit b78e4da

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.undertow.servlet.api.ServletContainer;
3737
import org.apache.jasper.servlet.JspServlet;
3838
import org.awaitility.Awaitility;
39+
import org.junit.jupiter.api.AfterEach;
3940
import org.junit.jupiter.api.Test;
4041
import org.mockito.InOrder;
4142

@@ -69,6 +70,13 @@ protected UndertowServletWebServerFactory getFactory() {
6970
return new UndertowServletWebServerFactory(0);
7071
}
7172

73+
@AfterEach
74+
void awaitClosureOfSslRelatedInputStreams() {
75+
// https://issues.redhat.com/browse/UNDERTOW-1705
76+
File resource = new File(this.tempDir, "test.txt");
77+
Awaitility.await().atMost(Duration.ofSeconds(30)).until(() -> (!resource.isFile()) || resource.delete());
78+
}
79+
7280
@Test
7381
void errorPage404() throws Exception {
7482
AbstractServletWebServerFactory factory = getFactory();

0 commit comments

Comments
 (0)