Skip to content

Commit e621613

Browse files
committed
PHPLIB-342: Explain why Watch may create its own Session object
MongoDB\Driver\Exception\RuntimeException does not conflict in this file, so we can also remove its alias.
1 parent 2076361 commit e621613

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Operation/Watch.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use MongoDB\Driver\ReadPreference;
2525
use MongoDB\Driver\Server;
2626
use MongoDB\Driver\Session;
27-
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
27+
use MongoDB\Driver\Exception\RuntimeException;
2828
use MongoDB\Exception\InvalidArgumentException;
2929
use MongoDB\Exception\UnexpectedValueException;
3030
use MongoDB\Exception\UnsupportedException;
@@ -110,10 +110,16 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
110110
}
111111
}
112112

113+
/* In the absence of an explicit session, create one to ensure that the
114+
* initial aggregation and any resume attempts can use the same session
115+
* ("implicit from the user's perspective" per PHPLIB-342). */
113116
if ( ! isset($options['session'])) {
114117
try {
115118
$options['session'] = $manager->startSession();
116-
} catch (DriverRuntimeException $e) {}
119+
} catch (RuntimeException $e) {
120+
/* We can ignore the exception, as libmongoc likely cannot
121+
* create its own session and there is no risk of a mismatch. */
122+
}
117123
}
118124

119125
$this->databaseName = (string) $databaseName;
@@ -132,7 +138,7 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
132138
* @param Server $server
133139
* @return ChangeStream
134140
* @throws UnsupportedException if collation or read concern is used and unsupported
135-
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
141+
* @throws RuntimeException for other driver errors (e.g. connection errors)
136142
*/
137143
public function execute(Server $server)
138144
{

0 commit comments

Comments
 (0)