Skip to content

Commit

Permalink
tls.c: Better tolerate short TLS writes.
Browse files Browse the repository at this point in the history
The existing retry policy for SSL_write returning
SSL_ERROR_WANT_WRITE was not very robust in handling
delayed writes from writing a large amount of data.
This improves this by significantly increasing
our tolerance and also resetting the counter when
progress is made.

This is still not perfect, and it would still be
better to do what the comments say.
  • Loading branch information
InterLinked1 committed Nov 13, 2023
1 parent 1056a4c commit 9addb13
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bbs/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,14 @@ static void *ssl_io_thread(void *unused)
if (!write_attempts++) { /* Log the first time. Debug, not warning, since this could happen legitimately */
bbs_debug(4, "SSL_write returned %ld (%s)\n", wres, ssl_strerror(err));
}
if (write_attempts < 1000) {
usleep(25); /* Don't make the loop super tight, it'll probably take several hunderd/thousand us anyways. */
if (write_attempts < 3000) {
/* Don't make the loop super tight, it'll probably take several hunderd/thousand us anyways,
* and we don't need to service I/O in realtime.
* Don't make it super loose either, we have other work we need to get on with. */
usleep(500);
continue;
}
/* This is more than a second without making any progress, abort. */
bbs_error("Max SSL_write retries (%d) exceeded\n", write_attempts);
MARK_DEAD(ssl);
needcreate = 1;
Expand All @@ -596,6 +600,9 @@ static void *ssl_io_thread(void *unused)
}
bbs_debug(6, "SSL_write returned %ld (%s)\n", wres, ssl_strerror(err));
break;
} else {
/* Reset any time we are able to make progress. */
write_attempts = 0;
}
}
} while (wres != ores);
Expand Down

0 comments on commit 9addb13

Please sign in to comment.