From 5c0bc080ea9175be54b4d1154081418727df0404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Sat, 14 Jan 2023 19:00:58 +0100 Subject: [PATCH] fix panic when Unfold sink return an error - fix issue #2600. When an Unfold sink return an error it is left in an invalid state. Calling after that flush/close cause the sink to panic due to re-calling a future already completed. This patch aims to leave the sink in a valid state and allow calling flush/close without causing a panic. --- futures-util/src/sink/unfold.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/futures-util/src/sink/unfold.rs b/futures-util/src/sink/unfold.rs index b5adf60ee0..165f80f1a0 100644 --- a/futures-util/src/sink/unfold.rs +++ b/futures-util/src/sink/unfold.rs @@ -73,7 +73,10 @@ where this.state.set(UnfoldState::Value { value: state }); Ok(()) } - Err(err) => Err(err), + Err(err) => { + this.state.set(UnfoldState::Empty); + Err(err) + } } } else { Ok(())