Hi, We are using Apache Tomcat 9.0 and frequently see logs related to CloseNowException in one of our applications. This exception occurs on multiple operating systems, including OpenSUSE, Ubuntu, and Windows, and in different parts of our codebase.
>From reading the Javadoc, our understanding is that this exception signals that a connection should be closed. We are unsure about the best way to handle it in our application. • Should we rethrow it so that Tomcat can handle it properly? • What would be the implications if we just catch and log the exception without rethrowing it? Could this interfere with Tomcat’s expected behavior in any way? We observe multiple variations of stack traces, but here is one example, truncated to omit internal details. Please note that the log entry is generated by our class, not by Tomcat: 2025-02-27 00:04:44.740 ERROR [ErrorFilter] [https-jsse-nio-443-exec-3604] [] [] Request by anonymous failed for GET https://www.nnn.nnnn org.apache.coyote.CloseNowException: Connection [1775817], Stream [27], This stream is in state [CLOSED_RST_RX] and is not writable at org.apache.coyote.http2.Stream.doStreamCancel(Stream.java:293) at org.apache.coyote.http2.Http2UpgradeHandler.reserveWindowSize(Http2UpgradeHandler.java:941) at org.apache.coyote.http2.Stream$StreamOutputBuffer.flush(Stream.java:1050) at org.apache.coyote.http2.Stream$StreamOutputBuffer.doWrite(Stream.java:965) at org.apache.coyote.http2.Http2OutputBuffer.doWrite(Http2OutputBuffer.java:57) at org.apache.coyote.Response.doWrite(Response.java:608) at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:333) at org.apache.catalina.connector.OutputBuffer.appendByteArray(OutputBuffer.java:750) at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:671) at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:380) at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:358) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:103) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:95) For additional context: Tomcat versions: multiple versions. The provided stack traces is from 9.0.87 but we see this in 9.0.98 as well • Operating systems affected: OpenSUSE, Ubuntu, Windows • HTTP/2 enabled: Yes, in the environments where this exception occurs We have reviewed the following resources without finding a clear answer: • Tomcat’s official documentation • Previous discussions in the user mailing list archives • Related posts on Stack Overflow We would appreciate guidance on the best approach to handling CloseNowException in our application to ensure compatibility with Tomcat. Thanks in advance for your help. Daniel