Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upMakes `write()` return `Err` when stream is closed #87
Conversation
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR! Can you clarify what you mean by "[the server] closes the stream?" Bidirectional QUIC streams are like TCP connections, in that the two halves can be closed independently of eachother, so if the server closes its send half, the client should still be able to freely write in the other direction until it closes that itself. The only way for a peer to close the half of a stream which a remote peer is writing to is by explicitly calling In general, my current feeling is that it's correct for quinn to panic on things that are always a result of a programming error in the local application, although it should never be possible for any remote (mis)behavior to cause a correct local application to panic. |
This comment has been minimized.
This comment has been minimized.
|
I would really prefer my libraries didn't decide when my program needs to panic, unless it's a incredibly unrecoverable situation such as a mutex being poisoned. Especially when the function returns a Result already. I'll try to come up with a more precise repro. |
This comment has been minimized.
This comment has been minimized.
|
In gitter, @djc made a good case for panicing on internal errors only, so I think I'm okay with switching to that paradigm. |
icefoxen
referenced this pull request
Nov 14, 2018
Closed
Returning `Result`s for a lot of rendering functions makes the api more complicated than needed. #512
Ralith
requested changes
Nov 16, 2018
While I'd like to find out more about your unexpectedly closed stream, we've deemed this PR reasonable in and of itself, so let's go ahead and get it ready to merge.
| @@ -2603,7 +2603,7 @@ impl Connection { | |||
| .streams | |||
| .streams | |||
| .get_mut(&stream) | |||
| .expect("stream already closed") | |||
| .ok_or(WriteError::Stopped {error_code: 0})? | |||
This comment has been minimized.
This comment has been minimized.
Ralith
Nov 16, 2018
•
Collaborator
| .ok_or(WriteError::Stopped {error_code: 0})? | |
| .ok_or(WriteError::Blocked)? |
This way we don't need to invent an error_code (which would normally come from the peer application), and the documentation/Display impl are even kind of accurate! There's also actually already precedent for this when a write is attempted after the connection is closed.
e: On further consideration, this might be gratuitously weird due to the handling of Blocked in the high-level bindings. Maybe better to introduce a new case in the enums?
icefoxen commentedNov 10, 2018
•
edited
...instead of panicking.
Basically, I have a server that accepts a client, opens a stream to it,
sends a message to it, and closes the stream. By accident I had the
client trying to send a message back on the same stream, which panicked,
on the
write(), 'cause it was already closed. This makes the writereturn
Errinstead.This doesn't QUITE work right still, I think it messes up the state
in the server side somehow. If I run a server, then run a client
the client properly says "that stream is closed" on the write.
But when I run it again without restarting the server then the client
never manages to connect to the server again, and times out.
The server never even sees an incoming connection.
This is still a step up for me, so I'm submitting this PR. XD
Oh, also, I don't know what error code the error should be.