Description
I profiled a service using hc5 to read chunked responses which are parsed using jackson directly from the entity stream. I've found that a new 4 KiB buffer is created to drain remaining bytes every time close is called, despite the read never producing any data because the next read discovers the terminating chunk.
This scenario is likely any time that self-terminating data is parsed, the consumer is able to stop reading prior to receiving an end-of-stream.
It's likely that sufficient data already exists in the SessionInputBuffer to avoid unnecessary buffers. To solve this issue it may be enough to attempt a single-byte read prior to using the buffer, or an efficient InputStream.skip(long) could be implemented.
A globally shared buffer would solve this, however there may be security concerns using a static buffer to dump trailing contents which may include sensitive data, accessible elsewhere in the jvm.