Skip to content

Web Client throws OutOfMemoryError when response is larger than 1GB and contains UTF-16 characters #35614

@mlichtblau

Description

@mlichtblau

We are observing OutOfMemoryErrors when the WebClient receives large responses containing characters that cannot be represented by Latin1 encoding.
This is especially critical, because the exception occurs here in decodeInternal before the data buffer is released and I suspect this is causing a memory leak.
I would expect a WebClientResponseException to be thrown and the data buffer to be released correctly.

Here is a demo that shows that WebClientResponseExceptions are thrown correctly for most cases (response larger 2GB, response larger maxInMemorySize), but not in the specific case where:

  • response within maxInMemorySize
  • AND response smaller Integer.MAX_VALUE
  • AND response larger Integer.MAX_VALUE >> 1 (StringUTF16.MAX_LENGTH)
  • AND response containing character that cannot be represented by Latin1.

response1500MBWithEmoji2000MBMaxMemoryThrowsOutOfMemoryError is the important test case.

If you have an idea where to throw a proper exception before attempting to create a String I would be happy to contribute.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anothertype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions