git: df20cc34b9f8 - main - tests/ssl_sendfile: fix flakyness under load

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 20:04:57 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=df20cc34b9f8bee3795dc7f636bddcc3df1eb2a0

commit df20cc34b9f8bee3795dc7f636bddcc3df1eb2a0
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-11-17 19:44:41 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-11-17 20:04:44 +0000

    tests/ssl_sendfile: fix flakyness under load
    
    When loopback TCP delivery is faster than our sending thread it may take
    several writes to full buffer reliably.
    
    PR:             299447
---
 tests/sys/kern/ssl_sendfile.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tests/sys/kern/ssl_sendfile.c b/tests/sys/kern/ssl_sendfile.c
index 8b8c1f95db25..f62105430514 100644
--- a/tests/sys/kern/ssl_sendfile.c
+++ b/tests/sys/kern/ssl_sendfile.c
@@ -482,7 +482,7 @@ ATF_TC_BODY(eagain_vs_eof, tc)
 {
 	struct ctx c;
 	char buf[16 * 1024];
-	ssize_t nread;
+	ssize_t nread, offset = 0;
 	int n;
 
 	common_init(&c);
@@ -492,7 +492,7 @@ ATF_TC_BODY(eagain_vs_eof, tc)
 	 * socket.  Internal sendfile(2) returns -1 and errno == EAGAIN.
 	 */
 	ATF_REQUIRE(pthread_mutex_lock(&c.mtx) == 0);
-	sendme_locked_wait(&c, 0, FSIZE, true);
+	sendme_locked_wait(&c, offset, FSIZE, true);
 	ATF_REQUIRE_MSG(c.sbytes > 0, "c.sbytes <= 0: %zd", c.sbytes);
 	ATF_REQUIRE(SSL_get_error(c.srv, c.sbytes) == 0);
 #if 0	/* see https://github.com/openssl/openssl/issues/29742 */
@@ -500,16 +500,23 @@ ATF_TC_BODY(eagain_vs_eof, tc)
 #endif
 
 	/*
-	 * Exercise second attempt on already full buffer.
+	 * Keep writing until both buffers are full.  May be executed just once
+	 * or may loop a few times in the case if our sending thread is slower
+	 * than loopback TCP processing.
 	 */
-	sendme_locked_wait(&c, 0, FSIZE, true);
-	ATF_REQUIRE_MSG(c.sbytes == -1, "c.sbytes != -1: %zd", c.sbytes);
+	do {
+		offset += c.sbytes;
+		sendme_locked_wait(&c, offset, FSIZE, true);
+#if 0	/* see https://github.com/openssl/openssl/issues/29742 */
+		ATF_REQUIRE(BIO_should_retry(SSL_get_wbio(c.srv)));
+#endif
+	} while (c.sbytes != -1);
 	ATF_REQUIRE(SSL_get_error(c.srv, c.sbytes) == SSL_ERROR_WANT_WRITE);
 	ATF_REQUIRE(BIO_should_retry(SSL_get_wbio(c.srv)));
 
 	/* Clear the buffer. */
 	nread = 0;
-	while (nread < c.sbytes &&
+	while (nread < offset &&
 	    (n = SSL_read_b(c.cln, buf, sizeof(buf))) > 0) {
 		ATF_REQUIRE(memcmp((char *)c.mfd + nread, buf, n) == 0);
 		nread += n;
@@ -555,4 +562,4 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, eagain_vs_eof);
 
 	return atf_no_error();
-}
\ No newline at end of file
+}