From 74cb4c419858decb4122b4c8efb9309502735564 Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fischer@muhq.space>
Date: Tue, 12 Jul 2022 12:10:59 +0200
Subject: [PATCH] [IoContext] do not use Future after allowing its destruction

When using the SINGLE_URING configuration the Future semaphore is used
to ensure that a forgotten Future is dropped after it is prepared and
not needed anymore.

Using the future after signaling its semaphore and thus allowing its
concurrent destruction is obviously broken.

Signal the semaphore after all preparation work is done.

Fixes: 9c0f2143c5c31f47cea587db4858b120c17cc5cb
---
 emper/io/IoContext.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/emper/io/IoContext.cpp b/emper/io/IoContext.cpp
index 2d8f2fa4..d92c9919 100644
--- a/emper/io/IoContext.cpp
+++ b/emper/io/IoContext.cpp
@@ -85,6 +85,11 @@ auto IoContext::prepareFutureChain(Future &future, unsigned chain_length) -> uns
 		if (IO_FORGOTTEN_FUTURES_SKIP_CQE) sqe->flags |= IOSQE_CQE_SKIP_SUCCESS;
 	}
 
+	if (future.isDependency()) {
+		LOGD("Prepare " << future << " as a dependency");
+		sqe->flags |= IOSQE_IO_LINK;
+	}
+
 	// If we use a single io_uring and a SubmitActor the submission and preparation
 	// of futures are decoupled.
 	// The Future may be used in a Fiber concurrently to the SubmitActor submitting it
@@ -102,11 +107,6 @@ auto IoContext::prepareFutureChain(Future &future, unsigned chain_length) -> uns
 		future.sem.signal();
 	}
 
-	if (future.isDependency()) {
-		LOGD("Prepare " << future << " as a dependency");
-		sqe->flags |= IOSQE_IO_LINK;
-	}
-
 	return total_chain_length;
 }
 
-- 
GitLab