Skip to content

Commit 3560d8d

Browse files
committed
CDRIVER-892 check write error in cluster_run_command
1 parent 48b6847 commit 3560d8d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/mongoc/mongoc-cluster.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ mongoc_cluster_fetch_stream_pooled (mongoc_cluster_t *cluster,
8585
bool reconnect_ok,
8686
bson_error_t *error);
8787

88+
89+
static const char *
90+
get_command_name (const bson_t *command)
91+
{
92+
bson_iter_t iter;
93+
94+
if (!bson_iter_init (&iter, command) ||
95+
!bson_iter_next (&iter)) {
96+
return NULL;
97+
}
98+
99+
return bson_iter_key (&iter);
100+
}
101+
102+
88103
/*
89104
*--------------------------------------------------------------------------
90105
*
@@ -115,6 +130,7 @@ _mongoc_cluster_run_command (mongoc_cluster_t *cluster,
115130
int32_t msg_len;
116131
bson_t reply_local;
117132
char ns[MONGOC_NAMESPACE_MAX];
133+
char error_message[sizeof error->message];
118134

119135
ENTRY;
120136

@@ -141,8 +157,16 @@ _mongoc_cluster_run_command (mongoc_cluster_t *cluster,
141157
_mongoc_rpc_gather(&rpc, &ar);
142158
_mongoc_rpc_swab_to_le(&rpc);
143159

144-
if (!mongoc_stream_writev(stream, (mongoc_iovec_t *)ar.data, ar.len,
145-
cluster->sockettimeoutms)) {
160+
if (!_mongoc_stream_writev_full (stream, (mongoc_iovec_t *)ar.data, ar.len,
161+
cluster->sockettimeoutms, error)) {
162+
/* add info about the command to writev_full's error message */
163+
bson_snprintf (error_message,
164+
sizeof error->message,
165+
"Failed to send \"%s\" command with database \"%s\": %s\n",
166+
get_command_name (command),
167+
db_name,
168+
error->message);
169+
bson_strncpy (error->message, error_message, sizeof error->message);
146170
GOTO(failure);
147171
}
148172

0 commit comments

Comments
 (0)