Skip to content
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

Redesign pooling mechanic #565

Merged
merged 13 commits into from Dec 4, 2022
Merged

Conversation

jsha
Copy link
Collaborator

@jsha jsha commented Nov 28, 2022

Introduce PoolReturner, a handle on an agent and a PoolKey that is capable of returning a Stream to a Pool. Make Streams keep track of their own PoolReturner, instead of having PoolReturnRead keep track of that information.

For the LimitedRead code path, get rid of PoolReturnRead. Instead, LimitedRead is responsible for returning its Stream to the Pool after its second-to-last read. In other words, LimitedRead will return the stream if the next read is guaranteed to return Ok(0).

Constructing a LimitedRead of size 0 is always wrong, because we could always just return the stream immediately. Change the size argument to NonZeroUsize to enforce that.

Remove the Done trait, which was only used for LimitedRead. It was used to try and make sure we returned the stream to the pool on exact reads, but was not reliable.

This does not yet move the ChunkDecoder code path away from PoolReturnRead. That requires a little more work.

Part 1 of #559.
Fixes #555.

@jsha jsha requested a review from algesten November 28, 2022 22:04
Copy link
Owner

@algesten algesten left a comment

Choose a reason for hiding this comment

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

Looks promising!

Some small comments.

src/pool.rs Show resolved Hide resolved
src/pool.rs Show resolved Hide resolved
src/pool.rs Show resolved Hide resolved
src/response.rs Outdated Show resolved Hide resolved
Copy link
Owner

@algesten algesten left a comment

Choose a reason for hiding this comment

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

Apart from that "recovery" in stream_to_reader, I think this looks great.

@jsha jsha mentioned this pull request Dec 3, 2022
@jsha jsha merged commit 9083d69 into algesten:main Dec 4, 2022
@jsha jsha deleted the limitedread-returns-itself branch December 4, 2022 07:43
@jsha jsha mentioned this pull request Jan 16, 2023
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.

Zero-length responses break connection reuse
2 participants