Skip to content

Fix couchbase threading crash and prepare for release #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 9.2.2
#### 29 July 2024
- __Driver Core__
- `Couchbasev4` Allow calling of `prepareToFork()` when driver is not initialized to allow switch between drivers.
- `Couchbasev4` Tell couchbase to reattach its threads if needed, while preparing to forking and on destruct.

## 9.2.1
#### 25 April 2024
- __Driver Core__
Expand Down
29 changes: 20 additions & 9 deletions lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve
$this->__parentConstruct($config, $instanceId, $em);
}

public function __destruct()
{
static::handleNotifyFork();
}


/**
* @return bool
Expand Down Expand Up @@ -164,6 +169,7 @@ public static function prepareToFork(): void
}

if (\version_compare(static::$extVersion, '4.2.1', '>=')) {
static::handleNotifyFork();
Cluster::notifyFork(ForkEvent::PREPARE);
}

Expand All @@ -188,15 +194,20 @@ protected function handleForkedProcess(): void
$this->connect(\posix_getppid());
}

if (\version_compare(static::$extVersion, '4.2.1', '>=')) {
if (static::$prepareToForkPPID === \posix_getpid()) {
Cluster::notifyFork(ForkEvent::PARENT);
} else {
Cluster::notifyFork(ForkEvent::CHILD);
}
static::$prepareToForkPPID = 0;
}
static::handleNotifyFork();
}
}
}

protected static function handleNotifyFork(): void
{
if (static::$prepareToForkPPID && \version_compare(static::$extVersion, '4.2.1', '>=')) {
if (static::$prepareToForkPPID === \posix_getpid()) {
Cluster::notifyFork(ForkEvent::PARENT);
} else {
Cluster::notifyFork(ForkEvent::CHILD);
}
static::$prepareToForkPPID = 0;
}
}

Expand All @@ -214,7 +225,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
/**
* CouchbaseBucket::get() returns a GetResult interface
*/
return $this->decodeDocument((array)$this->getCollection()->get($item->getEncodedKey())->content());
return $this->decodeDocument((array) $this->getCollection()->get($item->getEncodedKey())->content());
} catch (DocumentNotFoundException) {
return null;
}
Expand Down
Loading