Fix flakey SSH connection (#19439)

Fixes a bug due to the `select!` macro tossing futures that had
partially read messages, causing us to desync our message reading with
the input stream.

Release Notes:

- N/A

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Co-authored-by: conrad <conrad@zed.dev>
This commit is contained in:
Mikayla Maki 2024-10-18 15:41:43 -07:00 committed by GitHub
parent 30e081b3f7
commit 8a912726d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 92 additions and 84 deletions

View file

@ -2,7 +2,6 @@ use anyhow::Result;
use futures::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use prost::Message as _;
use rpc::proto::Envelope;
use std::mem::size_of;
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct MessageId(pub u32);
@ -30,8 +29,10 @@ pub async fn read_message<S: AsyncRead + Unpin>(
) -> Result<Envelope> {
buffer.resize(MESSAGE_LEN_SIZE, 0);
stream.read_exact(buffer).await?;
let len = message_len_from_buffer(buffer);
read_message_with_len(stream, buffer, len).await
let result = read_message_with_len(stream, buffer, len).await;
result
}
pub async fn write_message<S: AsyncWrite + Unpin>(