RFR: 8299015: Ensure that HttpResponse.BodySubscribers.ofFile writes all bytes
Daniel Fuchs
dfuchs at openjdk.org
Tue Dec 20 10:14:50 UTC 2022
On Tue, 20 Dec 2022 09:56:10 GMT, Chris Hegarty <chegar at openjdk.org> wrote:
>> src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java line 289:
>>
>>> 287: ByteBuffer[] buffers = items.toArray(Utils.EMPTY_BB_ARRAY);
>>> 288: while (bytesWritten < size) {
>>> 289: bytesWritten += out.write(buffers);
>>
>> Should we do something special here if no bytes are written, to avoid a busy loop?
>
>> Should we do something special here if no bytes are written, to avoid a busy loop?
>
> I wonder how / if this could occur in practice? From what I see elsewhere the simple, "don't check no bytes written", loop is common. ( It shouldn't be so hard/dangerous to use these gathering write APIs :-( )
I would expect that 0 can only be returned if the channel is configured non blocking. So maybe for our piece of mind we could throw an IOException if that happens, which would then be caught below and cause close() and subscription.cancel() to be called, and the result to be completed exceptionally?
-------------
PR: https://git.openjdk.org/jdk/pull/11722
More information about the net-dev
mailing list