Commit 25dd603
committed
Fix coroutine queue/array consistency: ensure coroutine is added to ASYNC_G(coroutines) immediately after enqueue
Move the addition of coroutine to ASYNC_G(coroutines) hash table to occur
immediately after adding to the coroutine_queue, before any callback invocations
that might throw exceptions.
This prevents a critical race condition where:
1. Coroutine is added to coroutine_queue (line 154-158)
2. Exception occurs in after_coroutine_enqueue or afterCoroutineEnqueue callbacks
3. Function returns NULL without adding coroutine to ASYNC_G(coroutines)
4. Scheduler later extracts coroutine from queue and tries to execute it
5. async_coroutine_execute() fails trying to remove non-existent entry from ASYNC_G(coroutines)
Changes:
- Move zend_hash_index_add_ptr() call from line 193 to line 166
- Move ZEND_ASYNC_INCREASE_COROUTINE_COUNT from line 199 to line 172
- Ensures atomicity: if coroutine is in queue, it's also in the hash table
- Callback errors now occur after coroutine is properly registered in both structures
This guarantees consistency between ASYNC_G(coroutine_queue) and ASYNC_G(coroutines).1 parent bd485bd commit 25dd603
1 file changed
+8
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
166 | 174 | | |
167 | 175 | | |
168 | 176 | | |
| |||
190 | 198 | | |
191 | 199 | | |
192 | 200 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
0 commit comments