RFR: 8371718: (sc) Channels.new{Input, Output}Stream can allocate unbounded memory for a socket channel

Alan Bateman alanb at openjdk.org
Mon Dec 8 19:21:19 UTC 2025


On Mon, 8 Dec 2025 19:10:42 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Clamp read and write to 128k bytes.

src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java line 83:

> 81:     // The maximum number of bytes to read/write per syscall to avoid needing
> 82:     // a huge buffer from the temporary buffer cache
> 83:     static final int MAX_ADAPTOR_BUFFER_SIZE = 128 * 1024;

The channel adaptors shouldn't be used the SocketImpl implementation. I think we add a MAX_BUFFER_SIZE constants to Streams.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28705#discussion_r2599830711


More information about the nio-dev mailing list