24
24
use MongoDB \Driver \ReadPreference ;
25
25
use MongoDB \Driver \Server ;
26
26
use MongoDB \Driver \Session ;
27
- use MongoDB \Driver \Exception \RuntimeException as DriverRuntimeException ;
27
+ use MongoDB \Driver \Exception \RuntimeException ;
28
28
use MongoDB \Exception \InvalidArgumentException ;
29
29
use MongoDB \Exception \UnexpectedValueException ;
30
30
use MongoDB \Exception \UnsupportedException ;
@@ -110,10 +110,16 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
110
110
}
111
111
}
112
112
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). */
113
116
if ( ! isset ($ options ['session ' ])) {
114
117
try {
115
118
$ 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
+ }
117
123
}
118
124
119
125
$ this ->databaseName = (string ) $ databaseName ;
@@ -132,7 +138,7 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
132
138
* @param Server $server
133
139
* @return ChangeStream
134
140
* @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)
136
142
*/
137
143
public function execute (Server $ server )
138
144
{
0 commit comments