Skip to content

Commit b346c4e

Browse files
committed
fix mutex unlock
1 parent 9f104e0 commit b346c4e

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

src/libmongoc/src/mongoc/mongoc-read-prefs.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,12 @@ assemble_query (const mongoc_read_prefs_t *read_prefs,
378378
break;
379379

380380
case MONGOC_TOPOLOGY_SHARDED:
381+
case MONGOC_TOPOLOGY_LOADBALANCED:
381382
_apply_read_preferences_mongos (read_prefs, query_bson, result);
382383
break;
383384

384385
case MONGOC_TOPOLOGY_UNKNOWN:
385386
case MONGOC_TOPOLOGY_DESCRIPTION_TYPES:
386-
case MONGOC_TOPOLOGY_LOADBALANCED:
387-
/* TODO (CDRIVER-4056): this is pending a question on pre-5.0 support and testing.
388-
* The spec says 5.0 is the minimum server version.
389-
* It is unclear if we can assume the backing server always supports OP_MSG.
390-
* I think the intent is we can, but there is no max wire version check.
391-
*/
392387
default:
393388
/* must not call _apply_read_preferences with unknown topology type */
394389
BSON_ASSERT (false);

src/libmongoc/src/mongoc/mongoc-topology.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,9 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
10161016

10171017
if (!selected_server) {
10181018
_mongoc_server_selection_error (
1019-
"No suitable server found in load balanced deployment",
1020-
NULL,
1021-
error);
1019+
"No suitable server found in load balanced deployment",
1020+
NULL,
1021+
error);
10221022
return 0;
10231023
}
10241024
}
@@ -1123,10 +1123,11 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
11231123
if (topology->description.type == MONGOC_TOPOLOGY_LOADBALANCED) {
11241124
/* Bypass server selection loop. Always select the only server. */
11251125
if (!selected_server) {
1126+
bson_mutex_unlock (&topology->mutex);
11261127
_mongoc_server_selection_error (
1127-
"No suitable server found in load balanced deployment",
1128-
NULL,
1129-
error);
1128+
"No suitable server found in load balanced deployment",
1129+
NULL,
1130+
error);
11301131
return 0;
11311132
}
11321133
}

src/libmongoc/tests/test-mongoc-loadbalanced.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include "test-libmongoc.h"
2121
#include "TestSuite.h"
2222

23-
static char *loadbalanced_uri (void) {
23+
static char *
24+
loadbalanced_uri (void)
25+
{
2426
return test_framework_getenv ("SINGLE_MONGOS_LB_URI");
2527
}
2628

@@ -65,7 +67,8 @@ test_loadbalanced_sessions_do_not_expire (void *unused)
6567
mongoc_client_session_destroy (session);
6668

6769
if (!bson_equal (lsid1, lsid2)) {
68-
test_error ("Session not reused: %s != %s", tmp_json (lsid1), tmp_json (lsid2));
70+
test_error (
71+
"Session not reused: %s != %s", tmp_json (lsid1), tmp_json (lsid2));
6972
}
7073

7174
bson_destroy (lsid1);
@@ -77,23 +80,24 @@ test_loadbalanced_sessions_do_not_expire (void *unused)
7780
static int
7881
skip_if_not_loadbalanced (void)
7982
{
80-
char *val = loadbalanced_uri ();
81-
if (!val) {
83+
if (test_framework_getenv_bool ("MONGOC_TEST_LOADBALANCED")) {
84+
return 1;
85+
} else {
8286
return 0;
8387
}
84-
bson_free (val);
85-
return 1;
8688
}
8789

8890
void
8991
test_loadbalanced_install (TestSuite *suite)
9092
{
91-
TestSuite_AddFull (suite, "/loadbalanced/sessions/supported",
93+
TestSuite_AddFull (suite,
94+
"/loadbalanced/sessions/supported",
9295
test_loadbalanced_sessions_supported,
9396
NULL /* ctx */,
9497
NULL /* dtor */,
9598
skip_if_not_loadbalanced);
96-
TestSuite_AddFull (suite, "/loadbalanced/sessions/do_not_expire",
99+
TestSuite_AddFull (suite,
100+
"/loadbalanced/sessions/do_not_expire",
97101
test_loadbalanced_sessions_do_not_expire,
98102
NULL /* ctx */,
99103
NULL /* dtor */,

src/libmongoc/tests/test-mongoc-sdam.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ _topology_has_description (mongoc_topology_description_t *topology,
3535
BSON_ASSERT (sd->set_name);
3636
ASSERT_CMPSTR (sd->set_name, set_name);
3737
}
38-
/* TODO (CDRIVER-4057) this should assert that a null setName means the server description also has no setName.
38+
/* TODO (CDRIVER-4057) this should assert that a null setName means the
39+
server description also has no setName.
3940
Uncomment this when CDRIVER-4057 is resolved.
4041
else if (sd->set_name) {
41-
test_error ("server: %s, expected NULL setName, got: %s", address, sd->set_name);
42+
test_error ("server: %s, expected NULL setName, got: %s", address,
43+
sd->set_name);
4244
}
4345
*/
4446
} else if (strcmp ("type", bson_iter_key (&server_iter)) == 0) {

0 commit comments

Comments
 (0)