Skip to content

Commit 77b44f9

Browse files
committed
async_scheduler_hook: make php_async_starting thread-local
It is the only channel handing a fresh fiber context its coroutine handle; as a plain static, one ZTS thread's write could be clobbered by another's before the first entry consumed it, starting a coroutine with a foreign handle.
1 parent 2ad9318 commit 77b44f9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

ext/async_scheduler_hook/async_scheduler_hook.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ static void php_async_record_current(bool ok, zval *retval)
413413
static zend_function php_async_root_function = { ZEND_INTERNAL_FUNCTION };
414414

415415
/* Set by the switcher before a first entry: a fresh context has no other way
416-
* to reach its handle. */
417-
static php_coroutine_t *php_async_starting = NULL;
416+
* to reach its handle. Thread-local: the write and the first-entry read must
417+
* stay on the same thread. */
418+
ZEND_TLS php_coroutine_t *php_async_starting = NULL;
418419

419420
/* First-run trampoline: install a VM stack, run the body, return to the last
420421
* switcher (the engine's trampoline marks the context DEAD). */

0 commit comments

Comments
 (0)