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

Fix panic: cannot consume from pending buffer #303

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 8 additions & 5 deletions src/futures/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,24 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
State::Flushing
} else {
let mut input = PartialBuffer::new(input);
let done = this.decoder.decode(&mut input, output).or_else(|err| {
let res = this.decoder.decode(&mut input, output).or_else(|err| {
// ignore the first error, occurs when input is empty
// but we need to run decode to flush
if first {
Ok(false)
} else {
Err(err)
}
})?;
});

if !first {
let len = input.written().len();
this.reader.as_mut().consume(len);
}

first = false;

let len = input.written().len();
this.reader.as_mut().consume(len);
if done {
if res? {
State::Flushing
} else {
State::Decoding
Expand Down
13 changes: 8 additions & 5 deletions src/tokio/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,24 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
State::Flushing
} else {
let mut input = PartialBuffer::new(input);
let done = this.decoder.decode(&mut input, output).or_else(|err| {
let res = this.decoder.decode(&mut input, output).or_else(|err| {
// ignore the first error, occurs when input is empty
// but we need to run decode to flush
if first {
Ok(false)
} else {
Err(err)
}
})?;
});

if !first {
let len = input.written().len();
this.reader.as_mut().consume(len);
}

first = false;

let len = input.written().len();
this.reader.as_mut().consume(len);
if done {
if res? {
State::Flushing
} else {
State::Decoding
Expand Down