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
This commit is contained in:
Andy Wilkinson 2020-05-14 12:45:18 +01:00
parent 5eabb0400c
commit b78e4dacec

View File

@ -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();