Skip to content

Commit c721869

Browse files
committed
CDRIVER-756: Improve debugging
Check return codes using <= Return how much we have written, even if the last vector wasn't even tried Plentyful traces Disable IO dumping
1 parent 4fcb6e3 commit c721869

File tree

4 files changed

+64
-21
lines changed

4 files changed

+64
-21
lines changed

src/mongoc/mongoc-socket.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ _mongoc_socket_try_sendv (mongoc_socket_t *sock, /* IN */
931931
# endif
932932
#endif
933933

934+
TRACE("Send %ld out of %ld bytes (errno=%d)", ret, iov->iov_len, errno);
934935
/*
935936
* Check to see if we have sent an iovec too large for sendmsg to
936937
* complete. If so, we need to fallback to the slow path of multiple
@@ -995,6 +996,7 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
995996

996997
for (;;) {
997998
sent = _mongoc_socket_try_sendv (sock, &iov [cur], iovcnt - cur);
999+
TRACE("Sent %ld (of %ld) out of iovcnt=%ld", sent, iov[cur].iov_len, iovcnt);
9981000

9991001
/*
10001002
* If we failed with anything other than EAGAIN or EWOULDBLOCK,
@@ -1004,7 +1006,7 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
10041006
if (sent == -1) {
10051007
if (!_mongoc_socket_errno_is_again (sock)) {
10061008
ret = -1;
1007-
goto CLEANUP;
1009+
GOTO(CLEANUP);
10081010
}
10091011
}
10101012

@@ -1019,6 +1021,7 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
10191021
* Subtract the sent amount from what we still need to send.
10201022
*/
10211023
while ((cur < iovcnt) && (sent >= (ssize_t)iov [cur].iov_len)) {
1024+
TRACE("still got bytes left: sent -= iov_len: %ld -= %ld", sent, iov[cur+1].iov_len);
10221025
sent -= iov [cur++].iov_len;
10231026
}
10241027

@@ -1027,27 +1030,31 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
10271030
* sending data over the socket.
10281031
*/
10291032
if (cur == iovcnt) {
1033+
TRACE("%s", "Finished the iovecs");
10301034
break;
10311035
}
10321036

10331037
/*
10341038
* Increment the current iovec buffer to its proper offset and adjust
10351039
* the number of bytes to write.
10361040
*/
1041+
TRACE("Seeked io_base+%ld", sent);
1042+
TRACE("Subtracting iov_len -= sent; %ld -= %ld", iov[cur].iov_len, sent);
10371043
iov [cur].iov_base = ((char *)iov [cur].iov_base) + sent;
10381044
iov [cur].iov_len -= sent;
1045+
TRACE("iov_len remaining %ld", iov[cur].iov_len);
10391046

10401047
BSON_ASSERT (iovcnt - cur);
10411048
BSON_ASSERT (iov [cur].iov_len);
10421049
} else if (OPERATION_EXPIRED (expire_at)) {
1043-
goto CLEANUP;
1050+
GOTO(CLEANUP);
10441051
}
10451052

10461053
/*
10471054
* Block on poll() until our desired condition is met.
10481055
*/
10491056
if (!_mongoc_socket_wait (sock->sd, POLLOUT, expire_at)) {
1050-
goto CLEANUP;
1057+
GOTO(CLEANUP);
10511058
}
10521059
}
10531060

src/mongoc/mongoc-stream-tls.c

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,10 @@ _mongoc_stream_tls_bio_read (BIO *b,
205205

206206
BSON_ASSERT (b);
207207
BSON_ASSERT (buf);
208+
ENTRY;
208209

209210
if (!(tls = b->ptr)) {
210-
return -1;
211+
RETURN (-1);
211212
}
212213

213214
errno = 0;
@@ -216,10 +217,11 @@ _mongoc_stream_tls_bio_read (BIO *b,
216217
BIO_clear_retry_flags (b);
217218

218219
if ((ret < 0) && MONGOC_ERRNO_IS_AGAIN (errno)) {
220+
MONGOC_DEBUG("set_retry_read");
219221
BIO_set_retry_read (b);
220222
}
221223

222-
return ret;
224+
RETURN (ret);
223225
}
224226

225227

@@ -247,27 +249,36 @@ _mongoc_stream_tls_bio_write (BIO *b,
247249
mongoc_stream_tls_t *tls;
248250
mongoc_iovec_t iov;
249251
int ret;
252+
ENTRY;
250253

251254
BSON_ASSERT (b);
252255
BSON_ASSERT (buf);
253256

254257
if (!(tls = b->ptr)) {
255-
return -1;
258+
RETURN (-1);
256259
}
257260

258261
iov.iov_base = (void *)buf;
259262
iov.iov_len = len;
260263

261264
errno = 0;
265+
TRACE("mongoc_stream_writev is expected to write: %d", len);
262266
ret = (int)mongoc_stream_writev (tls->base_stream, &iov, 1,
263267
tls->timeout_msec);
264268
BIO_clear_retry_flags (b);
265269

266-
if ((ret < 0) && MONGOC_ERRNO_IS_AGAIN (errno)) {
270+
if (len > ret) {
271+
TRACE("Returned short write: %d of %d", ret, len);
272+
} else {
273+
TRACE("Completed the %d", ret);
274+
}
275+
if (ret <= 0 && MONGOC_ERRNO_IS_AGAIN (errno)) {
276+
TRACE("%s", "Requesting a retry");
267277
BIO_set_retry_write (b);
268278
}
269279

270-
return ret;
280+
281+
RETURN (ret);
271282
}
272283

273284

@@ -416,10 +427,13 @@ static int
416427
_mongoc_stream_tls_close (mongoc_stream_t *stream)
417428
{
418429
mongoc_stream_tls_t *tls = (mongoc_stream_tls_t *)stream;
430+
int ret = 0;
431+
ENTRY;
419432

420433
BSON_ASSERT (tls);
421434

422-
return mongoc_stream_close (tls->base_stream);
435+
ret = mongoc_stream_close (tls->base_stream);
436+
RETURN (ret);
423437
}
424438

425439

@@ -459,6 +473,7 @@ _mongoc_stream_tls_write (mongoc_stream_tls_t *tls,
459473

460474
int64_t now;
461475
int64_t expire = 0;
476+
ENTRY;
462477

463478
BSON_ASSERT (tls);
464479
BSON_ASSERT (buf);
@@ -469,8 +484,10 @@ _mongoc_stream_tls_write (mongoc_stream_tls_t *tls,
469484
}
470485

471486
ret = BIO_write (tls->bio, buf, buf_len);
487+
TRACE("BIO_write returned %ld", ret);
472488

473-
if (ret < 0) {
489+
TRACE("I got ret: %ld and retry: %d", ret, BIO_should_retry (tls->bio));
490+
if (ret <= 0) {
474491
return ret;
475492
}
476493

@@ -488,7 +505,13 @@ _mongoc_stream_tls_write (mongoc_stream_tls_t *tls,
488505
}
489506
}
490507

491-
return ret;
508+
if (ret <= 0 && BIO_should_retry (tls->bio)) {
509+
if (tls->timeout_msec > 0) {
510+
TRACE("I do have %dmsec left", tls->timeout_msec);
511+
}
512+
}
513+
514+
RETURN (ret);
492515
}
493516

494517

@@ -545,6 +568,7 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
545568
BSON_ASSERT (tls);
546569
BSON_ASSERT (iov);
547570
BSON_ASSERT (iovcnt);
571+
ENTRY;
548572

549573
tls->timeout_msec = timeout_msec;
550574

@@ -590,18 +614,23 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
590614
* if we didn't buffer and have to send out of the iovec */
591615

592616
child_ret = _mongoc_stream_tls_write (tls, to_write, to_write_len);
617+
if (child_ret != to_write_len) {
618+
MONGOC_DEBUG("Got child_ret: %ld while to_write_len is: %ld",
619+
child_ret, to_write_len);
620+
}
593621

594622
if (child_ret < 0) {
595623
/* Buffer write failed, just return the error */
596-
return child_ret;
624+
TRACE("Returning what I had: %ld", ret);
625+
RETURN (ret);
597626
}
598627

599628
ret += child_ret;
600629

601630
if (child_ret < to_write_len) {
602631
/* we timed out, so send back what we could send */
603632

604-
return ret;
633+
RETURN (ret);
605634
}
606635

607636
to_write = NULL;
@@ -612,10 +641,12 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
612641
if (buf_head != buf_tail) {
613642
/* If we have any bytes buffered, send */
614643

644+
TRACE("buffered writing %ld", buf_tail - buf_head);
615645
child_ret = _mongoc_stream_tls_write (tls, buf_head, buf_tail - buf_head);
646+
TRACE("Got %ld written", child_ret);
616647

617648
if (child_ret < 0) {
618-
return child_ret;
649+
RETURN (child_ret);
619650
}
620651

621652
ret += child_ret;
@@ -625,7 +656,7 @@ _mongoc_stream_tls_writev (mongoc_stream_t *stream,
625656
mongoc_counter_streams_egress_add (ret);
626657
}
627658

628-
return ret;
659+
RETURN (ret);
629660
}
630661

631662

@@ -661,6 +692,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
661692
size_t iov_pos = 0;
662693
int64_t now;
663694
int64_t expire = 0;
695+
ENTRY;
664696

665697
BSON_ASSERT (tls);
666698
BSON_ASSERT (iov);
@@ -702,7 +734,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
702734
#else
703735
errno = ETIMEDOUT;
704736
#endif
705-
return -1;
737+
RETURN (-1);
706738
}
707739

708740
tls->timeout_msec = 0;
@@ -715,7 +747,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
715747

716748
if ((size_t)ret >= min_bytes) {
717749
mongoc_counter_streams_ingress_add(ret);
718-
return ret;
750+
RETURN (ret);
719751
}
720752

721753
iov_pos += read_ret;
@@ -726,7 +758,7 @@ _mongoc_stream_tls_readv (mongoc_stream_t *stream,
726758
mongoc_counter_streams_ingress_add(ret);
727759
}
728760

729-
return ret;
761+
RETURN (ret);
730762
}
731763

732764

src/mongoc/mongoc-stream.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,14 @@ _mongoc_stream_writev_full (mongoc_stream_t *stream,
306306
size_t total_bytes = 0;
307307
int i;
308308
ssize_t r;
309+
ENTRY;
309310

310311
for (i = 0; i < iovcnt; i++) {
311312
total_bytes += iov[i].iov_len;
312313
}
313314

314315
r = mongoc_stream_writev(stream, iov, iovcnt, timeout_msec);
316+
TRACE("writev returned: %d", r);
315317

316318
if (r < 0) {
317319
if (error) {
@@ -324,16 +326,16 @@ _mongoc_stream_writev_full (mongoc_stream_t *stream,
324326
"Failure during socket delivery: %s", errstr);
325327
}
326328

327-
return false;
329+
RETURN(false);
328330
}
329331

330332
if (r != total_bytes) {
331333
bson_set_error (error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_SOCKET,
332334
"Failure to send all requested bytes (only sent: %ld/%ld in %dms) during socket delivery",
333335
(int64_t)r, (int64_t)total_bytes, timeout_msec);
334336

335-
return false;
337+
RETURN(false);
336338
}
337339

338-
return true;
340+
RETURN(true);
339341
}

src/mongoc/mongoc-trace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ BSON_BEGIN_DECLS
4040
bson_string_t *str, *astr; \
4141
int32_t _i; \
4242
uint8_t _v; \
43+
break; \
4344
mongoc_log(MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, \
4445
" %s = %p [%d]", #_n, _b, (int)_l); \
4546
str = bson_string_new(NULL); \
@@ -81,6 +82,7 @@ BSON_BEGIN_DECLS
8182
unsigned _k = 0; \
8283
size_t _l = 0; \
8384
uint8_t _v; \
85+
break; \
8486
for (_i = 0; _i < _iovcnt; _i++) { \
8587
_l += _iov[_i].iov_len; \
8688
} \

0 commit comments

Comments
 (0)