-
-
Notifications
You must be signed in to change notification settings - Fork 21
Do not generate artificial "broken pipe" errors #73
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
Conversation
My logic here is that it should never be forbidden to send another request into the underlying stream. If |
`closed` flag is set when there is no more data to read from the stream. It does not mean that no more requests can be written into the stream. If the stream is closed for writing, `write_all` call will return this error, there is no need to emulate it.
e32ffdf
to
363dfd9
Compare
This is essentially reverting 68f21e5. So maybe there is a reason not to send requests when we cannot receive responses, then maybe I should write a documentation comment with a reason instead. |
What's the motivation for this? IIUC TCP closes both directions of the stream at the same time, it is not possible to only close one half. So once you read 0 bytes the stream is closed in all directions. I suspect there's not much harm to do this, but what's the expected gain? I thought this was purely a fast-path for the expected behaviour. Even if you were able to still write, you'd not be able to read any response since there is already this closed marker forcing the return of EOF (effectively this closed marker makes the ImapStream "fused"). |
It is possible to call There is no guarantee though that async-imap runs over TCP. It can already run over TLS or SOCKS5 connection, and there is nothing preventing usage of the library over QUIC, unix sockets and all kinds of tunnels, so TCP should not be assumed. There are definitely types of streams that can be closed one-way, and there are even streams that can be reopened as described in std::io::Read documentation. The original reason I made this PR is that during debugging of #66 closed flag was erroneously set, but resulted in a misleading write error while in fact the socket was not closed in any direction. Even with the bug fixed, it may be not the only case where this happens, because there may be other bugs or middleboxes inserting FIN flag. I will probably redo this PR trying to remove the |
I'm still not sure why you'd want to send requests if you can't send responses anymore. But all valid points. Anyway, the second half of what you say makes a lot of sense: to not manually track if the stream is usable or not so completely removing the I don't really mind this PR itself I guess, the original PR in which I introduce this commit already mentioned that it was optional as it shouldn't really change things (but yes, does change things in the face of bugs). |
I guess the one reason to maybe keep it in, for now, is that it makes things symmetric: if you stop reading you also stop writing. |
The bug may even be not in our code, but in a middlebox injecting The I will merge this PR as is now, and complete |
I am also not sure it is possible to receive EPIPE from a |
I have investigated further why |
closed
flag is set when there is no more data to read from the stream. It does not mean that no more requests can be written into the stream. If the stream is closed for writing,write_all
call will return this error, there is no need to emulate it.