Support the ongoing development of Laravel.io →
Cache
Last updated 3 months ago.
0

Issue is still an issue however we found that it is related to forking the laravel process.

We found that the attached test breaks if you take out the call to Cache::getStore()->getRedis()->purge(); So we started running reconnecting to redis after each fork and on the main thread, but we are still seeing the issue intermittently.

---------------------- UNIT TEST -------------------

/**
 * @test
 */
public function break_redis_cache()
{
    DB::reconnect('main');
    DB::reconnect('tenant');
    for ($i = 0; $i < 10; ++$i) {
        $pid = pcntl_fork();
        if ($pid) {
            if ($pid < 0) {
                throw new IndexingException('Failed to fork during Elastic indexing.');
            }

            $pids[$pid] = $pid;
        } else {
            DB::reconnect('main');
            DB::reconnect('tenant');
            Cache::getStore()->getRedis()->purge();
            for ($j = 0; $j < 20; ++$j) {
                $sleep = random_int(0, 15);
                usleep($sleep);
                Cache::tags(CacheTags::ELASTICSEARCH_REFRESH_REQUIRED)->add('logs', 1, 60);
            }
            exit();
        }
    }

    while (count($pids) > 0) {
        usleep(300);
        foreach ($pids as $pid) {
            $res = pcntl_waitpid($pid, $status, WNOHANG);
            if ($res === -1 || $res > 0) {
                unset($pids[$pid]);
            }
        }
    }

    $this->assertTrue(true);
}
Last updated 10 months ago.
0

Sign in to participate in this thread!

Cloudways

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.