diff --git a/main/sched.c b/main/sched.c
index 4443497c51af1e91573d4df8fc0d0b2aec00925c..033d238c7f198e65e7b81bdddf584a8ff4f8e434 100644
--- a/main/sched.c
+++ b/main/sched.c
@@ -497,7 +497,9 @@ int _ast_sched_del(struct ast_sched_context *con, int id, const char *file, int
 		/* Wait for executing task to complete so that caller of ast_sched_del() does not
 		 * free memory out from under the task.
 		 */
-		ast_cond_wait(&s->cond, &con->lock);
+		while (con->currently_executing && (id == con->currently_executing->id)) {
+			ast_cond_wait(&s->cond, &con->lock);
+		}
 		/* Do not sched_release() here because ast_sched_runq() will do it */
 	}