Skip to content

Commit 19bfb1a

Browse files
committed
PHPC-553: Check for connection exceptions in exec and SS methods
executeCommand(), executeQuery(), and selectServer() did not check for a global exception after executing via libmongoc, which meant that connection and SSL exceptions might end up as the previous exception where they could be easily ignored. This makes these methods consistent with executeBulkWrite(), which happens to be used in our SSL tests where we check for such exceptions.
1 parent cca7d04 commit 19bfb1a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

php_phongo.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, const p
618618
if (!mongoc_cursor_next(cursor, &doc)) {
619619
bson_error_t error;
620620

621+
/* Check for connection related exceptions */
622+
if (EG(exception)) {
623+
mongoc_cursor_destroy(cursor);
624+
return false;
625+
}
626+
621627
/* Could simply be no docs, which is not an error */
622628
if (mongoc_cursor_error(cursor, &error)) {
623629
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
@@ -652,6 +658,12 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, const bson_t
652658
if (!mongoc_cursor_next(cursor, &doc)) {
653659
bson_error_t error;
654660

661+
/* Check for connection related exceptions */
662+
if (EG(exception)) {
663+
mongoc_cursor_destroy(cursor);
664+
return false;
665+
}
666+
655667
if (mongoc_cursor_error(cursor, &error)) {
656668
mongoc_cursor_destroy(cursor);
657669
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);

src/MongoDB/Manager.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ PHP_METHOD(Manager, selectServer)
284284
phongo_server_init(return_value, intern->client, selected_server->id TSRMLS_CC);
285285
mongoc_server_description_destroy(selected_server);
286286
} else {
287+
/* Check for connection related exceptions */
288+
if (EG(exception)) {
289+
return;
290+
}
291+
287292
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "%s", error.message);
288293
}
289294
}

0 commit comments

Comments
 (0)