Skip to content

Forked Process Hanging Forever When Logging is Enabled #221

@deminy

Description

@deminy

When logging is enabled in the Couchbase PHP SDK v4, a forked process hangs indefinitely. However, when logging is disabled, the process runs successfully and exits as expected.

Steps to reproduce the issue: https://github.com/deminy/couchbase-issues/tree/couchbase4/issue-8

Test code used:

<?php

/**
 * The test script creates a child process that waits for 5 seconds and then exits.
 *
 * Usage:
 *     # When logging is disabled, the script runs successfully:
 *     docker compose exec -ti app php -d couchbase.log_level= ./test.php
 *
 *     # When logging is enabled, the script hangs indefinitely:
 *     docker compose exec -ti app php -d couchbase.log_level=warning ./test.php
 */

declare(strict_types=1);

$pid = pcntl_fork();
if ($pid === -1) {
    echo 'Could not fork.', PHP_EOL;
    exit(1);
}
if ($pid === 0) {
    echo 'I am the child (pid: ' . posix_getpid() . ').', PHP_EOL;
    sleep(5);
    exit(0);
}

echo "I'm the parent.", PHP_EOL;
while (pcntl_wait($status, WNOHANG) === 0) {
    sleep(1);
}
echo "Child process #{$pid} has finished execution.", PHP_EOL;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions