Skip to content

Commit

Permalink
Merge pull request #7 from srjlewis/master
Browse files Browse the repository at this point in the history
Fix couchbase threading crash and prepare for release
  • Loading branch information
Geolim4 authored Sep 1, 2024
2 parents d57cba0 + 7be58bd commit 65f0c77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
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

0 comments on commit 65f0c77

Please sign in to comment.