Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RqLive wrongly assumes the stream has ended when no data is aviable #1300

Open
laeubi opened this issue Jun 21, 2024 · 0 comments
Open

RqLive wrongly assumes the stream has ended when no data is aviable #1300

laeubi opened this issue Jun 21, 2024 · 0 comments

Comments

@laeubi
Copy link

laeubi commented Jun 21, 2024

org.takes.rq.RqLive.data(InputStream, Opt<Integer>, boolean) has the following code

} else if (available && input.available() <= 0) {
ret = new Opt.Single<>(-1);
} else {

this is wrong, as it indicates that the stream has reached EOF but it simply means the buffer is empty. See also the javadoc here:

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

So in case of 0 return value one can simply not tell anything, so at best one can return EMPTY here.

But looking at the code I don't see how this ever is useful in the parsing here, as even if the buffer is empty now, all one can do is to wait for one byte so blocking I/O seems the only option here.

Another pitfall is that here:

while (data.get() > 0) {

it assumes EOF also when the read byte is == 0, even though it should not happen and is an error in the http stream, a zero byte can be read from a stream and is not an EOF!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant