Skip to content

Commit

Permalink
fix: close stream on first error
Browse files Browse the repository at this point in the history
tokio::sync::broadcast will continue after telling how many items were
lost, which seems likely with the small buffer and quickly firing more
than the buffer elements.
  • Loading branch information
Joonas Koivunen committed Mar 25, 2020
1 parent cb49ee8 commit 090a3ee
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions http/src/v0/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ async fn inner_subscribe<T: IpfsTypes>(
};

// map recv errors into the StreamError and flatten
let mut errored = false;
rx.into_stream()
.map(|res| res.map_err(|_| StreamError::Recv).and_then(|res| res))
.take_while(move |res| {
// return until the first error
!std::mem::replace(&mut errored, res.is_err())
})
}

/// Shovel task takes items from the [`SubscriptionStream`], formats them and passes them on to
Expand Down

0 comments on commit 090a3ee

Please sign in to comment.