Skip to content

Commit aa607cd

Browse files
committed
CDRIVER-650 crash after replset reconnect
1 parent 8ef31e5 commit aa607cd

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/mongoc/mongoc-cluster.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ _mongoc_cluster_select (mongoc_cluster_t *cluster,
637637
bson_return_val_if_fail(rpcs_len, NULL);
638638
bson_return_val_if_fail(hint <= cluster->nodes_len, NULL);
639639

640-
nodes = bson_malloc(sizeof(*nodes) * cluster->nodes_len);
640+
nodes = bson_malloc0(sizeof(*nodes) * cluster->nodes_len);
641641
scores = bson_malloc(sizeof(*scores) * cluster->nodes_len);
642642

643643
/*
@@ -723,16 +723,25 @@ _mongoc_cluster_select (mongoc_cluster_t *cluster,
723723
/*
724724
* Apply the hint if the client knows who they would like to continue
725725
* communicating with.
726+
*
727+
* TODO: after an initial query a cursor sets its hint to an index in the
728+
* nodes array, but _mongoc_cluster_reconnect may resize the array or
729+
* rearrange servers and the cursor sends its getmore to the wrong server,
730+
* causing a server error "cursor not found". Fixed by the topology
731+
* rewrite in 1.2.x.
726732
*/
727733
if (hint) {
728-
if (!nodes[hint - 1]) {
734+
if ((hint - 1) >= cluster->nodes_len || !nodes[hint - 1]) {
729735
bson_set_error(error,
730736
MONGOC_ERROR_CLIENT,
731737
MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEER,
732738
"Requested node (%u) is not available.",
733739
hint);
740+
node = NULL;
741+
} else {
742+
node = nodes[hint - 1];
734743
}
735-
node = nodes[hint - 1];
744+
736745
goto CLEANUP;
737746
}
738747

src/mongoc/mongoc-stream.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ mongoc_stream_check_closed (mongoc_stream_t *stream)
282282

283283
ENTRY;
284284

285-
bson_return_val_if_fail(stream, -1);
285+
if (!stream) {
286+
return true;
287+
}
286288

287289
ret = stream->check_closed(stream);
288290

0 commit comments

Comments
 (0)