Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit cc36931

Browse files
authored
sc-transaction-handler: Fix potential crashes on exit (#12807)
This fixes some potential crashes in the stream handling in `sc-transaction-handler`.
1 parent 357c363 commit cc36931

File tree

1 file changed

+9
-7
lines changed
  • client/network/transactions/src

1 file changed

+9
-7
lines changed

client/network/transactions/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,13 @@ impl TransactionsHandlerPrototype {
172172

173173
let handler = TransactionsHandler {
174174
protocol_name: self.protocol_name,
175-
propagate_timeout: Box::pin(interval(PROPAGATE_TIMEOUT)),
175+
propagate_timeout: (Box::pin(interval(PROPAGATE_TIMEOUT))
176+
as Pin<Box<dyn Stream<Item = ()> + Send>>)
177+
.fuse(),
176178
pending_transactions: FuturesUnordered::new(),
177179
pending_transactions_peers: HashMap::new(),
178180
service,
179-
event_stream,
181+
event_stream: event_stream.fuse(),
180182
peers: HashMap::new(),
181183
transaction_pool,
182184
from_controller,
@@ -229,7 +231,7 @@ pub struct TransactionsHandler<
229231
> {
230232
protocol_name: ProtocolName,
231233
/// Interval at which we call `propagate_transactions`.
232-
propagate_timeout: Pin<Box<dyn Stream<Item = ()> + Send>>,
234+
propagate_timeout: stream::Fuse<Pin<Box<dyn Stream<Item = ()> + Send>>>,
233235
/// Pending transactions verification tasks.
234236
pending_transactions: FuturesUnordered<PendingTransaction<H>>,
235237
/// As multiple peers can send us the same transaction, we group
@@ -240,7 +242,7 @@ pub struct TransactionsHandler<
240242
/// Network service to use to send messages and manage peers.
241243
service: S,
242244
/// Stream of networking events.
243-
event_stream: Pin<Box<dyn Stream<Item = Event> + Send>>,
245+
event_stream: stream::Fuse<Pin<Box<dyn Stream<Item = Event> + Send>>>,
244246
// All connected peers
245247
peers: HashMap<PeerId, Peer<H>>,
246248
transaction_pool: Arc<dyn TransactionPool<H, B>>,
@@ -268,7 +270,7 @@ where
268270
pub async fn run(mut self) {
269271
loop {
270272
futures::select! {
271-
_ = self.propagate_timeout.next().fuse() => {
273+
_ = self.propagate_timeout.next() => {
272274
self.propagate_transactions();
273275
},
274276
(tx_hash, result) = self.pending_transactions.select_next_some() => {
@@ -278,15 +280,15 @@ where
278280
warn!(target: "sub-libp2p", "Inconsistent state, no peers for pending transaction!");
279281
}
280282
},
281-
network_event = self.event_stream.next().fuse() => {
283+
network_event = self.event_stream.next() => {
282284
if let Some(network_event) = network_event {
283285
self.handle_network_event(network_event).await;
284286
} else {
285287
// Networking has seemingly closed. Closing as well.
286288
return;
287289
}
288290
},
289-
message = self.from_controller.select_next_some().fuse() => {
291+
message = self.from_controller.select_next_some() => {
290292
match message {
291293
ToHandler::PropagateTransaction(hash) => self.propagate_transaction(&hash),
292294
ToHandler::PropagateTransactions => self.propagate_transactions(),

0 commit comments

Comments
 (0)