diff --git a/main/sched.c b/main/sched.c
index d50a31e56329372a0e84797137c3c747e54c51d4..062b2fd96e2c4e1adba141708a33c95afc199298 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 */
 	}