You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pipe p = new Pipe(1000);
Okio.buffer(p.sink()).write(new byte[10]).flush();
// This will block indefinitely:
Okio.buffer(p.source()).inputStream().readNBytes(10);
read(buf, 0, 10) --> returns 10, do another iteration
read(buf, 10, 0) --> gets stuck
IMO it's a reasonable implementation of readNBytes.
When we call read(0), RealBufferedSource.read() will call PipeSource.read(8192), which will block as it should.
If RealBufferedSource.read() could return immediately when length=0, we won't get blocked.
The text was updated successfully, but these errors were encountered:
cgrushko
changed the title
PipeSource.read() with length=0 blocks until there's some data
RealBufferedSource.read() with length=0 blocks until there's some data, breaking InputStream.readNBytes
May 6, 2024
Yeah, good advice. Wanna send a pull request? Otherwise I’m happy to fix it.
It's a bit of a process to get the CLA signed for me, so I'd appreciate if you could take it.
Also would like to take the opportunity to thank you folks for writing and maintaining okio and okhttp - it's an amazing piece of software :)
Repro:
The code in JDK 21+35 LTS is:
which effectively calls
read(buf, 0, 10) --> returns 10, do another iteration
read(buf, 10, 0) --> gets stuck
IMO it's a reasonable implementation of readNBytes.
When we call
read(0)
, RealBufferedSource.read() will call PipeSource.read(8192), which will block as it should.If RealBufferedSource.read() could return immediately when length=0, we won't get blocked.
The text was updated successfully, but these errors were encountered: