RFR: 8299015: Ensure that HttpResponse.BodySubscribers.ofFile writes all bytes [v6]
Daniel Jeliński
djelinski at openjdk.org
Tue Dec 20 22:03:55 UTC 2022
On Tue, 20 Dec 2022 14:53:11 GMT, Chris Hegarty <chegar at openjdk.org> wrote:
>> The implementation of `BodySubscribers.ofFile` does not correctly handle the case of a short gathering write. The write should be retried until all the bytes have been written to the underlying file.
>>
>> This is generally not an issue that would occur very frequently, since the `IOV_MAX` is commonly 1024 on Mac/Linux, and 16 on Windows. However, it is clearly a bug, and should be fixed.
>
> Chris Hegarty has updated the pull request incrementally with one additional commit since the last revision:
>
> fix catch
StackOverflow is telling me that FileChannel writes are always blocking, so a `write` call may only return zero if there are no bytes to write in any of the buffers. This could happen if the same buffer appeared twice on the list, or if some other thread modified the buffers while we were writing. These situations are not very likely to happen.
That being said, I think I'd implement the method as something like:
do {
out.write(buffers);
} while (Utils.hasRemaining(buffers));
this addresses both the possible failure modes, and leaves the math out of the picture.
-------------
PR: https://git.openjdk.org/jdk/pull/11722
More information about the net-dev
mailing list