Repository navigation
Conversation
Fix phpGH-25611 A context inherited through fork kept using the parent's epoll instance, so the child's registrations and removals reached the parent and wait() dereferenced watcher pointers from the other process. The context now rebuilds its backend on first use in a new process.
iliaal
left a comment
There was a problem hiding this comment.
Rebuilding the backend on first use in the child makes sense. I’d hold this until registration failures are handled. I forced one EPOLL_CTL_ADD to return ENOSPC. The watcher still reported active, but two consecutive waits missed its readable socket.
| ZEND_HASH_FOREACH_VAL(context->watchers, zval *zv) { | ||
| php_io_poll_watcher_object *watcher = PHP_POLL_WATCHER_OBJ_FROM_ZV(zv); | ||
| if (!watcher->disarmed) { | ||
| php_poll_add(ctx, (int) watcher->fd, watcher->watched_events, watcher); |
There was a problem hiding this comment.
Please check php_poll_add() here. Only replace context->ctx and set owner_pid after every armed watcher has been registered. On failure, discard the new backend and propagate its error so the next call can retry.
| fclose($reader); | ||
| exit(0); | ||
| } | ||
| pcntl_waitpid($pid, $status); |
There was a problem hiding this comment.
Can we check that the child exited normally with status zero? It emits no output in this case, so the test can pass even if the child dies during cleanup.
| $watcher = pt_stream_poll_add($context, $reader, [Event::Read], 'inherited'); | ||
| $pid = pcntl_fork(); | ||
| if ($pid === 0) { | ||
| $watcher->modifyEvents([Event::Read, Event::OneShot]); |
There was a problem hiding this comment.
Can we make wait() the child’s first context operation and assert that it returns the inherited watcher? modifyEvents() can re-register a missing watcher, and the child currently checks readiness only on the newly added one.
| return false; | ||
| } | ||
| if (php_poll_init(ctx) != SUCCESS) { | ||
| php_poll_destroy(ctx); |
There was a problem hiding this comment.
Can we save php_poll_get_error(ctx) before destroying ctx and pass it through to the exception, as the constructor does? Otherwise callers lose the reason initialization failed after a fork.
|
@devnexen don't merge - I want to review it first |
bukka
left a comment
There was a problem hiding this comment.
I don't like that many getpid() calls. I think we should hook it up to php_child_init() and do some sort of counter there.
Fix GH-25611
A context inherited through fork kept using the parent's epoll instance, so the child's registrations and removals reached the parent and wait() dereferenced watcher pointers from the other process. The context now rebuilds its backend on first use in a new process.