Skip to content

Conversation

@duncanista
Copy link
Contributor

@duncanista duncanista commented May 30, 2024

How?

Created a new from_stream method, which reads headers until content-length is found, and proceeds to read the exact remaining body size.

Motivation

  • Data loss and timeouts were happening due to a stream hanging waiting for data
  • Stream sometimes received the data chunked, which we were never reading.

First developed in #256, also SVLS-4932

Screenshot 2024-05-31 at 2 39 34 PM

read properly from the stream so we can read every byte, retry 3 times in case theres no data
also some integration tests, moving away from mocking `TcpStream`, since signature changed
@duncanista duncanista marked this pull request as ready for review May 30, 2024 20:27
@duncanista duncanista requested a review from a team as a code owner May 30, 2024 20:27
let content_length = parser
.headers
.get("content-length")
.expect("unfallible")
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to expect here? can't we just drop the request if it's malformed or something broke in our assumption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The loop before that ensures that the key exist, which means that this is infallible, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I think that's okay. It just makes me nervous

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 could definitely add another if let Some(...) block if that makes you feel more confident

fn handle_stream(
stream: &mut impl Read,
mut buf: [u8; 262_144],
stream: &TcpStream,
Copy link
Contributor

Choose a reason for hiding this comment

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

ah yeah I made this change in my branch too, a bit easier to handle than receiving a generic which implements Read.

@duncanista duncanista merged commit 09c473c into main May 31, 2024
@duncanista duncanista deleted the jordan.gonzalez/bottlecap/fix-stream-buffering branch May 31, 2024 19:53
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.

3 participants