Skip to content

OutputStreamContentSource.AsyncOutputStream rethrows already thrown exception #12029

@hwanders

Description

@hwanders

Jetty version(s)
12.0.11

Jetty Environment
core

Java version/vendor (use: java -version)
OpenJDK 17.0.10

OS type/version
Windows

Description
Executing a JettyClientHttpRequest throws an IllegalArgumentException with message Self-suppression not permitted if a SocketTimeoutException occurs when writing the response.

This is similar to #11736.

Reason

  1. In JettyClientHttpRequest.executeInternal an OutputStream is constructed from requestContent.getOutputStream() and the body is written to it
  2. That stream is of type OutputStreamContentSource.AsyncOutputStream
  3. During writing of the body, a flush might be performed triggering AsyncOutputStream.write
  4. The write delegates to AsyncOutput.write and the SocketTimeoutException may arise (let's assume that)
  5. That exception is caught and written to persistentFailure and thrown (and rethrown) in AsyncOutputStream.write.
  6. JettyClientHttpRequest.executeInternal's try-with-resources-block notices the exception and tries to close the output stream
  7. Closing the stream again causes a flush which repeats the persistentFailure
  8. Java notices that the try-with-resources block's finally-block throws and wants to suppress the original exception (from the write) - but it's exactly the same exception again, which leads to the IllegalArgumentException

How to reproduce?
Try to send a large enough request to an unresponsive host causing an intermediate flush.

Metadata

Metadata

Assignees

Labels

BugFor general bugs on Jetty side

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions