Skip to content

Commit

Permalink
Fix panic: cannot consume from pending buffer
Browse files Browse the repository at this point in the history
Fixed #298

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Oct 15, 2024
1 parent 535fc9c commit cb122d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/futures/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,22 @@ 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)
}
})?;
});

first = false;

let len = input.written().len();
this.reader.as_mut().consume(len);
if done {

if res? {
State::Flushing
} else {
State::Decoding
Expand Down
7 changes: 4 additions & 3 deletions src/tokio/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,22 @@ 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)
}
})?;
});

first = false;

let len = input.written().len();
this.reader.as_mut().consume(len);
if done {

if res? {
State::Flushing
} else {
State::Decoding
Expand Down

0 comments on commit cb122d4

Please sign in to comment.