Skip to content

Add option to keep connections open after error status codes - #1135

Closed
ooeunz wants to merge 1 commit into
apache:mainfrom
ooeunz:dropConnectionOnErrorStatus
Closed

ooeunz wants to merge 1 commit into
apache:mainfrom
ooeunz:dropConnectionOnErrorStatus

Conversation

@ooeunz

@ooeunz ooeunz commented Nov 1, 2026

Copy link
Copy Markdown

Problem

The HTTP/1.1 connector forces the connection to close after a response with a status code of 400, 408, 411, 413, 414, 500, 501 or 503 (Http11Processor.statusDropsConnection()). When these responses are frequent, clients have to keep re-establishing connections, which increases HTTP resource usage. There is currently no way to turn this off.

Change

Add a dropConnectionOnErrorStatus attribute to the HTTP/1.1 connector. It defaults to true, so existing behaviour is unchanged.

<Connector port="8080" protocol="HTTP/1.1" dropConnectionOnErrorStatus="false" />

When set to false, a status code on its own no longer closes the connection. This applies to status codes set by an application or the container, such as sendError(500).

What still closes the connection

Connections are still closed when re-using them would not be safe, whatever the value of the attribute:

  • The request could not be parsed, or is otherwise invalid (400).
  • The request uses an unsupported transfer encoding (501).
  • The connector is paused (503).
  • An exception is thrown during processing (500).
  • An error occurs after the response was committed.
  • The unread request body exceeds maxSwallowSize.
  • An Expect: 100-continue request body was not fully read.

These responses still include Connection: close.

Trade-off

With the attribute set to false, a client that repeatedly triggers errors can hold a connection for longer, and Tomcat may swallow up to maxSwallowSize bytes of unread body per request. maxKeepAliveRequests and keepAliveTimeout still apply. This is why the default retains the current behaviour.

Testing

Added tests to TestHttp11Processor for:

  • the default behaviour
  • connection re-use with the attribute disabled
  • swallowing an unread body before the next request on the same connection
  • the cases above that must still close: invalid request line, missing Host, unsupported transfer encoding, and a body exceeding maxSwallowSize

ant validate and the tests under org.apache.coyote.http11 pass on NIO with JDK 21. The full test suite was not run.

The HTTP/1.1 connector closes the connection after a response with a
status code of 400, 408, 411, 413, 414, 500, 501 or 503. Clients then have
to re-establish the connection, which increases HTTP resource usage when
these responses are frequent.

Add the dropConnectionOnErrorStatus connector attribute so this behaviour
can be disabled. The default of true retains the current behaviour.
Connections are still closed when it is not safe to re-use them.
@markt-asf

Copy link
Copy Markdown
Contributor

No. See #579.

@markt-asf markt-asf closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants