From cdb7544b764d78dc6b15e6f0be779aa24577d977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Er=C3=A8be=20-=20Romain=20Gerard?= Date: Sun, 15 Jan 2023 01:32:14 +0100 Subject: [PATCH] fix panic when Unfold sink return an error (#2686) - 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 330a068c31..dea1307b66 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(())