RFR: 8257736: InputStream from BodyPublishers.ofInputStream() leaks when IOE happens

Daniel Fuchs dfuchs at openjdk.java.net
Fri Dec 4 15:15:15 UTC 2020


On Fri, 4 Dec 2020 14:32:41 GMT, Yasumasa Suenaga <ysuenaga at openjdk.org> wrote:

>> src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java line 426:
>> 
>>> 424:                     is.close();
>>> 425:                 } catch (IOException ex2) {}
>>> 426:                 return -1;
>> 
>> } catch (IOException ex2) {}
>>                 return -1;
>> 
>> I wonder if the first exception `ex` should actually be rethrown here instead of returning `-1`. Have you tried to explore this possibility?
>
> `read()` is not have IOE as checked exception, and also currently IOE is ignored.
> So I ignored IOE at `close()` in this PR to minimize side-effect.

Right. But I am not sure that is the right thing to do. If InputStream::read throws then it's likely that the request body will be missing some bytes, so the request should probably be cancelled/aborted at this point - rather than having a truncated body sent to the server.

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

PR: https://git.openjdk.java.net/jdk/pull/1614


More information about the net-dev mailing list