Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions protocol/src/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,15 @@ where
bytes_read,
} => {
while *bytes_read < NUM_LENGTH_BYTES {
*bytes_read += self.reader.read(&mut length_bytes[*bytes_read..]).await?;
let len = self.reader.read(&mut length_bytes[*bytes_read..]).await?;
if len == 0 {
return Err(std::io::Error::new(
std::io::ErrorKind::ConnectionAborted,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with ConnectionAborted here. ConnectionReset is an alternative. Happy to be convinced to use ConnectionReset if someone has strong feelings about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion here, ConnectionAborted is fine with me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use UnexpectedEof? It looks like that is what tokio bubbles up in similar scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this too, but found the Rust stdlib docs to not to be a perfect fit for our case? https://doc.rust-lang.org/std/io/enum.ErrorKind.html#variant.UnexpectedEof

An error returned when an operation could not be completed because an “end of file” was reached prematurely.
This typically means that an operation could only succeed if it read a particular number of bytes but only a smaller number of bytes could be read.

(but also don't really care too much personally)

"read zero bytes",
)
.into());
}
*bytes_read += len;
}

let packet_bytes_len = self.inbound_cipher.decrypt_packet_len(*length_bytes);
Expand All @@ -417,7 +425,15 @@ where
bytes_read,
} => {
while *bytes_read < packet_bytes.len() {
*bytes_read += self.reader.read(&mut packet_bytes[*bytes_read..]).await?;
let len = self.reader.read(&mut packet_bytes[*bytes_read..]).await?;
if len == 0 {
return Err(std::io::Error::new(
std::io::ErrorKind::ConnectionAborted,
"read zero bytes",
)
.into());
}
*bytes_read += len;
}

let plaintext_len = InboundCipher::decryption_buffer_len(packet_bytes.len());
Expand Down