Skip to content

Commit

Permalink
Fix panic when all chains are removed (#1422)
Browse files Browse the repository at this point in the history
* Fix panic when all chains are removed

* PR link
  • Loading branch information
tomaka authored Nov 27, 2023
1 parent f41b80e commit 33d96b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 7 additions & 9 deletions light-base/src/network_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,16 +978,14 @@ async fn background_task<TPlat: PlatformRef>(mut task: BackgroundTask<TPlat>) {
.map_or(WakeUpReason::ForegroundClosed, WakeUpReason::Message)
};
let message_for_chain_received = async {
if !task.messages_rx.is_empty() {
let (chain_id, message) = task
.messages_rx
.next()
.await
.unwrap_or_else(|| unreachable!());
WakeUpReason::MessageForChain(chain_id, message)
} else {
// Note that when the last entry of `messages_rx` yields `None`, `messages_rx`
// itself will yield `None`. For this reason, we can't use
// `task.messages_rx.is_empty()` to determine whether `messages_rx` will
// yield `None`.
let Some((chain_id, message)) = task.messages_rx.next().await else {
future::pending().await
}
};
WakeUpReason::MessageForChain(chain_id, message)
};
let message_from_task_received = async {
let (connection_id, message) = task.tasks_messages_rx.next().await.unwrap();
Expand Down
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fix panic in network service when all chains are removed. ([#1422](https://github.com/smol-dot/smoldot/pull/1422))

## 2.0.11 - 2023-11-27

### Changed
Expand Down

0 comments on commit 33d96b9

Please sign in to comment.