Include HTTP/2 stream idle timeouts in IOExceptionMapper

This commit is contained in:
Chris Eager
2024-03-05 17:51:14 -06:00
committed by Chris Eager
parent 3cc740cda3
commit 9f6a6d7f5b
2 changed files with 54 additions and 2 deletions

View File

@@ -21,8 +21,19 @@ public class IOExceptionMapper implements ExceptionMapper<IOException> {
public Response toResponse(IOException e) {
if (!(e.getCause() instanceof java.util.concurrent.TimeoutException)) {
logger.warn("IOExceptionMapper", e);
} else if (e.getCause().getMessage().startsWith("Idle timeout expired")) {
return Response.status(Response.Status.REQUEST_TIMEOUT).build();
} else {
// Some TimeoutExceptions are because the connection is idle, but are only distinguishable using the exception
// message
final String message = e.getCause().getMessage();
final boolean idleTimeout =
message != null &&
// org.eclipse.jetty.io.IdleTimeout
(message.startsWith("Idle timeout expired")
// org.eclipse.jetty.http2.HTTP2Session
|| (message.startsWith("Idle timeout") && message.endsWith("elapsed")));
if (idleTimeout) {
return Response.status(Response.Status.REQUEST_TIMEOUT).build();
}
}
return Response.status(503).build();