-
Notifications
You must be signed in to change notification settings - Fork 397
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
fix: re-use BufReader across poll_next invocations, instead of creating a new one #1093
base: main
Are you sure you want to change the base?
Conversation
we re-create the BufReader on each poll_next which might cause the buffer state to be lost between polls move BufReader to a field of ByteTransport and re-use the same BufReader and see if buffer state is preserved
this avoids re-allocating the a new buffer, and having to regrow its capacity
|
hmmm can't replicate this error on my local machine or when running in a docker container |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Let's leave a note imo on what we think this is about, something like
// The buf reader will accumulate from stdin or similar stream
// we clear one line at each iteration of poll_next from the buffer
crates/mcp-server/src/lib.rs
Outdated
#[pin] | ||
writer: W, | ||
buf: Vec<u8>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if my understanding of the issue is correct, we don't need to keep this as a member and clear it below? seems simpler to instantiate a new one in each poll next instead. but let me know if i am missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works. i didn't pull the latest changes 🤦🏼
docs: add comments explaining why reader is BufReader
re-use a single
BufReader
acrosspoll_next
calls, instead of creating a new one each timealso create a re-useableVec
that we read into, and usestd::mem::take
once we have a full line to read offstd::mem::take
will also clear the vectorthis hopefully adresses some odd timing issues we saw when communicating with mcp servers