Skip to content

GH-656: shrink ChannelPipedInputStream buffer after all data is read - #913

Merged
tomaswolf merged 1 commit into
apache:masterfrom
arimu1:fix/656-piped-input-buffer-eof
Aug 29, 2026
Merged

GH-656: shrink ChannelPipedInputStream buffer after all data is read#913
tomaswolf merged 1 commit into
apache:masterfrom
arimu1:fix/656-piped-input-buffer-eof

Conversation

@arimu1

@arimu1 arimu1 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #656

Summary

  • When all piped data has been consumed, replace the internal ByteArrayBuffer with a fresh default-sized buffer instead of calling compact(), which only resets positions and leaves the large backing array allocated
  • On eof() with no unread data, apply the same shrink so cached SSH sessions do not retain ~512 KB per channel after command completion

Test plan

  • Added bufferShrinksAfterAllDataRead regression test (64 KiB payload; asserts backing array returns to ByteArrayBuffer.DEFAULT_SIZE after drain + EOF)
  • Existing ChannelPipedInputStreamTest cases pass
  • Command: mvn -pl sshd-core -am -DskipTests install -q && mvn -pl sshd-core -Dtest=ChannelPipedInputStreamTest test (Java 21, Maven 3.9.16)

Made with Cursor

… read

Replace compact() with a fresh default-sized ByteArrayBuffer when the
pipe is drained, including on EOF with no pending data, so cached SSH
sessions do not retain large backing arrays.
@tomaswolf
tomaswolf merged commit 7436b1c into apache:master Aug 29, 2026
7 checks passed
@tomaswolf

Copy link
Copy Markdown
Member

Thank you!

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.

How Do I Clear the Buffer After a Cache Session Is Used to Avoid Memory Usage?

2 participants