Skip to content

Commit

Permalink
Work around file handle leak when Undertow is stopped
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wilkinsona committed May 14, 2020
1 parent 5eabb04 commit b78e4da
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -36,6 +36,7 @@
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;

Expand Down Expand Up @@ -69,6 +70,13 @@ protected UndertowServletWebServerFactory getFactory() {
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();
Expand Down

0 comments on commit b78e4da

Please sign in to comment.