Skip to content

Commit b27a5da

Browse files
committed
CDRIVER-630: default_stream_initiator can block forever in TLS handshake
1 parent 1f87486 commit b27a5da

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/mongoc/mongoc-async-cmd-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int
9292
mongoc_async_cmd_tls_setup (mongoc_stream_t *stream,
9393
int *events,
9494
void *ctx,
95+
int32_t timeout_msec,
9596
bson_error_t *error);
9697
#endif
9798

src/mongoc/mongoc-async-cmd.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ int
6060
mongoc_async_cmd_tls_setup (mongoc_stream_t *stream,
6161
int *events,
6262
void *ctx,
63+
int32_t timeout_msec,
6364
bson_error_t *error)
6465
{
6566
mongoc_stream_t *tls_stream;
@@ -69,7 +70,7 @@ mongoc_async_cmd_tls_setup (mongoc_stream_t *stream,
6970
tls_stream = mongoc_stream_get_base_stream (tls_stream)) {
7071
}
7172

72-
if (mongoc_stream_tls_do_handshake (tls_stream, 0)) {
73+
if (mongoc_stream_tls_do_handshake (tls_stream, timeout_msec)) {
7374
if (mongoc_stream_tls_check_cert (tls_stream, host)) {
7475
return 1;
7576
} else {
@@ -231,8 +232,14 @@ mongoc_async_cmd_destroy (mongoc_async_cmd_t *acmd)
231232
mongoc_async_cmd_result_t
232233
_mongoc_async_cmd_phase_setup (mongoc_async_cmd_t *acmd)
233234
{
235+
int64_t now;
236+
int32_t timeout_msec;
237+
238+
now = bson_get_monotonic_time ();
239+
timeout_msec = (acmd->expire_at - now) / 1000;
240+
234241
switch (acmd->setup (acmd->stream, &acmd->events, acmd->setup_ctx,
235-
&acmd->error)) {
242+
timeout_msec, &acmd->error)) {
236243
case -1:
237244
return MONGOC_ASYNC_CMD_ERROR;
238245
break;

src/mongoc/mongoc-async-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef int
5353
(*mongoc_async_cmd_setup_t)(mongoc_stream_t *stream,
5454
int *events,
5555
void *ctx,
56+
int32_t timeout_msec,
5657
bson_error_t *error);
5758

5859

tests/test-mongoc-stream-tls-error.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ test_mongoc_tls_hangup (void)
222222
* 5. confirms that it times out
223223
* 6. shuts down
224224
*/
225-
#ifdef TODO_CDRIVER_630
226225
static void *
227226
handshake_stall_client (void *ptr)
228227
{
@@ -243,7 +242,7 @@ handshake_stall_client (void *ptr)
243242
mongoc_mutex_unlock (&data->cond_mutex);
244243

245244
uri_str = bson_strdup_printf (
246-
"mongodb://localhost:%u/?ssl=true&connecttimeoutms=%" PRId64,
245+
"mongodb://localhost:%u/?ssl=true&serverselectiontimeoutms=200&connecttimeoutms=%" PRId64,
247246
data->server_port, connect_timeout_ms);
248247

249248
client = mongoc_client_new (uri_str);
@@ -318,7 +317,6 @@ test_mongoc_tls_handshake_stall (void)
318317
ASSERT (cr.result == SSL_TEST_SUCCESS);
319318
ASSERT (sr.result == SSL_TEST_SUCCESS);
320319
}
321-
#endif
322320

323321
void
324322
test_stream_tls_error_install (TestSuite *suite)
@@ -328,8 +326,6 @@ test_stream_tls_error_install (TestSuite *suite)
328326
TestSuite_Add (suite, "/TLS/hangup", test_mongoc_tls_hangup);
329327
#endif
330328

331-
#ifdef TODO_CDRIVER_630
332329
TestSuite_Add (suite, "/TLS/handshake_stall",
333330
test_mongoc_tls_handshake_stall);
334-
#endif
335331
}

0 commit comments

Comments
 (0)