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

Handle source close while reading on Pipe #1574

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicolashaan
Copy link

Handle source close while reading on Pipe.
Does it look like a legit behavior to implement?

@swankjesse
Copy link
Collaborator

It’s not safe to close a source you’re currently reading. You want pipe.cancel() instead.

@nicolashaan
Copy link
Author

I understand this is not safe but the API is allowing it anyway.
Then why not mimic the behavior of Java socket that throws in such a case, and where closing the input stream is closing the socket?
At this moment the read will block indefinitely until the Sink is closed or the Pipe is cancelled.

@swankjesse
Copy link
Collaborator

We’d be better off if we had a Source.cancel() API, but I didn’t do that at the time.

Java’s InputStream uses synchronized to kind of support this, but we also don’t do synchronized in Okio. This is a feature!

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

Successfully merging this pull request may close these issues.

2 participants