|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 | 20 | import java.io.IOException;
|
| 21 | +import java.net.SocketException; |
21 | 22 | import java.net.URISyntaxException;
|
22 | 23 | import java.nio.charset.Charset;
|
23 | 24 | import java.nio.charset.StandardCharsets;
|
|
57 | 58 | import org.apache.coyote.ProtocolHandler;
|
58 | 59 | import org.apache.coyote.http11.AbstractHttp11Protocol;
|
59 | 60 | import org.apache.http.HttpResponse;
|
| 61 | +import org.apache.http.client.HttpClient; |
60 | 62 | import org.apache.http.conn.HttpHostConnectException;
|
| 63 | +import org.apache.http.impl.client.HttpClients; |
61 | 64 | import org.apache.jasper.servlet.JspServlet;
|
62 | 65 | import org.apache.tomcat.JarScanFilter;
|
63 | 66 | import org.apache.tomcat.JarScanType;
|
@@ -582,8 +585,40 @@ void whenServerIsShuttingDownGracefullyThenNewConnectionsCannotBeMade() throws E
|
582 | 585 | assertThat(shutdownResult.get()).isEqualTo(false);
|
583 | 586 | blockingServlet.admitOne();
|
584 | 587 | assertThat(request.get()).isInstanceOf(HttpResponse.class);
|
585 |
| - this.webServer.stop(); |
586 | 588 | assertThat(unconnectableRequest.get()).isInstanceOf(HttpHostConnectException.class);
|
| 589 | + this.webServer.stop(); |
| 590 | + } |
| 591 | + |
| 592 | + @Test |
| 593 | + void whenServerIsShuttingDownARequestOnAnIdleConnectionResultsInConnectionReset() throws Exception { |
| 594 | + AbstractServletWebServerFactory factory = getFactory(); |
| 595 | + Shutdown shutdown = new Shutdown(); |
| 596 | + shutdown.setGracePeriod(Duration.ofSeconds(5)); |
| 597 | + factory.setShutdown(shutdown); |
| 598 | + BlockingServlet blockingServlet = new BlockingServlet(); |
| 599 | + this.webServer = factory.getWebServer((context) -> { |
| 600 | + Dynamic registration = context.addServlet("blockingServlet", blockingServlet); |
| 601 | + registration.addMapping("/blocking"); |
| 602 | + registration.setAsyncSupported(true); |
| 603 | + }); |
| 604 | + HttpClient httpClient = HttpClients.createMinimal(); |
| 605 | + this.webServer.start(); |
| 606 | + int port = this.webServer.getPort(); |
| 607 | + Future<Object> keepAliveRequest = initiateGetRequest(httpClient, port, "/blocking"); |
| 608 | + blockingServlet.awaitQueue(); |
| 609 | + blockingServlet.admitOne(); |
| 610 | + assertThat(keepAliveRequest.get()).isInstanceOf(HttpResponse.class); |
| 611 | + Future<Object> request = initiateGetRequest(port, "/blocking"); |
| 612 | + blockingServlet.awaitQueue(); |
| 613 | + initiateGracefulShutdown(); |
| 614 | + Future<Object> idleConnectionRequest = initiateGetRequest(httpClient, port, "/blocking"); |
| 615 | + blockingServlet.admitOne(); |
| 616 | + Object response = request.get(); |
| 617 | + assertThat(response).isInstanceOf(HttpResponse.class); |
| 618 | + Object idleConnectionRequestResult = idleConnectionRequest.get(); |
| 619 | + assertThat(idleConnectionRequestResult).isInstanceOf(SocketException.class); |
| 620 | + assertThat((SocketException) idleConnectionRequestResult).hasMessage("Connection reset"); |
| 621 | + this.webServer.stop(); |
587 | 622 | }
|
588 | 623 |
|
589 | 624 | @Override
|
|
0 commit comments