Skip to content

Commit 65f0c77

Browse files
authored
Merge pull request #7 from srjlewis/master
Fix couchbase threading crash and prepare for release
2 parents d57cba0 + 7be58bd commit 65f0c77

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 9.2.2
2+
#### 29 July 2024
3+
- __Driver Core__
4+
- `Couchbasev4` Allow calling of `prepareToFork()` when driver is not initialized to allow switch between drivers.
5+
- `Couchbasev4` Tell couchbase to reattach its threads if needed, while preparing to forking and on destruct.
6+
17
## 9.2.1
28
#### 25 April 2024
39
- __Driver Core__

lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve
9090
$this->__parentConstruct($config, $instanceId, $em);
9191
}
9292

93+
public function __destruct()
94+
{
95+
static::handleNotifyFork();
96+
}
97+
9398

9499
/**
95100
* @return bool
@@ -164,6 +169,7 @@ public static function prepareToFork(): void
164169
}
165170

166171
if (\version_compare(static::$extVersion, '4.2.1', '>=')) {
172+
static::handleNotifyFork();
167173
Cluster::notifyFork(ForkEvent::PREPARE);
168174
}
169175

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

191-
if (\version_compare(static::$extVersion, '4.2.1', '>=')) {
192-
if (static::$prepareToForkPPID === \posix_getpid()) {
193-
Cluster::notifyFork(ForkEvent::PARENT);
194-
} else {
195-
Cluster::notifyFork(ForkEvent::CHILD);
196-
}
197-
static::$prepareToForkPPID = 0;
198-
}
197+
static::handleNotifyFork();
198+
}
199+
}
200+
}
201+
202+
protected static function handleNotifyFork(): void
203+
{
204+
if (static::$prepareToForkPPID && \version_compare(static::$extVersion, '4.2.1', '>=')) {
205+
if (static::$prepareToForkPPID === \posix_getpid()) {
206+
Cluster::notifyFork(ForkEvent::PARENT);
207+
} else {
208+
Cluster::notifyFork(ForkEvent::CHILD);
199209
}
210+
static::$prepareToForkPPID = 0;
200211
}
201212
}
202213

@@ -214,7 +225,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
214225
/**
215226
* CouchbaseBucket::get() returns a GetResult interface
216227
*/
217-
return $this->decodeDocument((array)$this->getCollection()->get($item->getEncodedKey())->content());
228+
return $this->decodeDocument((array) $this->getCollection()->get($item->getEncodedKey())->content());
218229
} catch (DocumentNotFoundException) {
219230
return null;
220231
}

0 commit comments

Comments
 (0)