2424use MongoDB \Driver \ReadPreference ;
2525use MongoDB \Driver \Server ;
2626use MongoDB \Driver \Session ;
27- use MongoDB \Driver \Exception \RuntimeException as DriverRuntimeException ;
27+ use MongoDB \Driver \Exception \RuntimeException ;
2828use MongoDB \Exception \InvalidArgumentException ;
2929use MongoDB \Exception \UnexpectedValueException ;
3030use 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