mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-24 09:16:12 +01:00
Fix infinite loop in read_from_rx
This commit is contained in:
parent
af0dd99ef4
commit
2477a0f945
2 changed files with 24 additions and 1 deletions
|
@ -25,6 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Retry requests that previously returned `RetryAfter(_)` error
|
- Retry requests that previously returned `RetryAfter(_)` error
|
||||||
- `RequestError::RetryAfter` now has a `Duration` field instead of `i32`
|
- `RequestError::RetryAfter` now has a `Duration` field instead of `i32`
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix never ending loop that caused programs that used `Throttling` to never stop, see issue [#535][issue535]
|
||||||
|
|
||||||
|
[issue535]: https://github.com/teloxide/teloxide/issues/535
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- `UserId::{url, is_anonymous, is_channel, is_telegram}` convenience functions ([#197][pr197])
|
- `UserId::{url, is_anonymous, is_channel, is_telegram}` convenience functions ([#197][pr197])
|
||||||
|
|
|
@ -365,9 +365,26 @@ async fn read_from_rx<T>(rx: &mut mpsc::Receiver<T>, queue: &mut Vec<T>, rx_is_c
|
||||||
while queue.len() < queue.capacity() {
|
while queue.len() < queue.capacity() {
|
||||||
match rx.try_recv() {
|
match rx.try_recv() {
|
||||||
Ok(req) => queue.push(req),
|
Ok(req) => queue.push(req),
|
||||||
Err(TryRecvError::Disconnected) => *rx_is_closed = true,
|
Err(TryRecvError::Disconnected) => {
|
||||||
|
*rx_is_closed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
// There are no items in queue.
|
// There are no items in queue.
|
||||||
Err(TryRecvError::Empty) => break,
|
Err(TryRecvError::Empty) => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[tokio::test]
|
||||||
|
async fn issue_535() {
|
||||||
|
let (tx, mut rx) = tokio::sync::mpsc::channel(1);
|
||||||
|
|
||||||
|
// Close channel
|
||||||
|
drop(tx);
|
||||||
|
|
||||||
|
// Previously this caused an infinite loop
|
||||||
|
super::read_from_rx::<()>(&mut rx, &mut Vec::new(), &mut false).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue