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.
We are observing
OutOfMemoryErrors when theWebClientreceives large responses containing characters that cannot be represented byLatin1encoding.This is especially critical, because the exception occurs here in
decodeInternalbefore the data buffer is released and I suspect this is causing a memory leak.I would expect a
WebClientResponseExceptionto 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 largermaxInMemorySize), but not in the specific case where:maxInMemorySizeInteger.MAX_VALUEInteger.MAX_VALUE >> 1(StringUTF16.MAX_LENGTH)response1500MBWithEmoji2000MBMaxMemoryThrowsOutOfMemoryErroris 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.