Skip to content

Commit 14896f8

Browse files
committed
add tests for fiber cancellation scenarios and coroutine behavior
1 parent 6d2cd7f commit 14896f8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Zend/zend_fibers.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,11 @@ static void zend_fiber_resume_coroutine(zend_fiber *fiber, zval *value, zval *ex
981981
return;
982982
}
983983

984+
if (ZEND_COROUTINE_IS_FINISHED(fiber->coroutine)) {
985+
zend_throw_error(zend_ce_fiber_error, "Cannot resume a fiber that is not suspended");
986+
return;
987+
}
988+
984989
if (UNEXPECTED(fiber->resume_event == NULL)) {
985990
zend_throw_error(zend_ce_fiber_error, "Cannot resume a fiber that has not been started");
986991
return;
@@ -1117,6 +1122,12 @@ static void coroutine_entry_point(void)
11171122
fiber->flags |= ZEND_FIBER_FLAG_BAILOUT;
11181123
}
11191124

1125+
if (fiber && fiber->resume_event) {
1126+
zend_async_event_t *resume_event_base = &fiber->resume_event->base;
1127+
fiber->resume_event = NULL;
1128+
ZEND_ASYNC_EVENT_RELEASE(resume_event_base);
1129+
}
1130+
11201131
// Cleanup fcall (Except in the case when the Fiber itself has already cleaned up this structure)
11211132
if (EXPECTED(fcall && !(fiber && fiber->fcall == NULL))) {
11221133

@@ -1283,7 +1294,6 @@ static void zend_fiber_object_destroy(zend_object *object)
12831294
// while the coroutine is already running. In this case, we cancel the coroutine.
12841295
//
12851296
zend_coroutine_t *coroutine = fiber->coroutine;
1286-
fiber->coroutine = NULL;
12871297
coroutine->extended_data = NULL;
12881298

12891299
if (ZEND_COROUTINE_IS_FINISHED(coroutine) || false == ZEND_COROUTINE_IS_STARTED(coroutine)) {

0 commit comments

Comments
 (0)