patches and low-level development discussion
 help / color / mirror / code / Atom feed
* [PATCH v2] release/checks/integration: handle partial sends
@ 2025-11-29 18:00 Alyssa Ross
  2025-11-29 20:02 ` Yureka
  2025-11-30 16:08 ` Alyssa Ross
  0 siblings, 2 replies; 3+ messages in thread
From: Alyssa Ross @ 2025-11-29 18:00 UTC (permalink / raw)
  To: devel; +Cc: Demi Marie Obenour, Yureka Lilian

Sometimes we see a test failure that looks like this:

	unexpected connection data: qemu-system-aarch64: terminating on signal 15 from pid 184 ()

I think this is because, now that the nc command in the networking
integration test has a timeout, it's possible for it to time out after
having opened the connection, but before having written all its input
to it.  Therefore, ignore connections that send a prefix of the
expected data (including nothing), and just wait for the next
connection rather than failing if that happens.

Closes: https://spectrum-os.org/lists/archives/spectrum-devel/875xbl33vw.fsf@alyssa.is/
Fixes: c61b297 ("release/checks/integration: add nc timeout")
Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
v2: close connections when finished reading.
v1: https://spectrum-os.org/lists/archives/spectrum-devel/20251129163521.717709-2-hi@alyssa.is/

 release/checks/integration/networking.c | 50 +++++++++++++++----------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/release/checks/integration/networking.c b/release/checks/integration/networking.c
index 97d7895..df76ec5 100644
--- a/release/checks/integration/networking.c
+++ b/release/checks/integration/networking.c
@@ -57,32 +57,44 @@ static int setup_server(void)
 
 static void expect_connection(int listener)
 {
-	int conn_fd;
-	FILE *conn;
+	int conn, r;
 	char msg[7];
 	size_t len;
 
-	fputs("waiting for server connection\n", stderr);
-	if ((conn_fd = accept(listener, nullptr, nullptr)) == -1) {
-		perror("accept");
-		exit(EXIT_FAILURE);
-	}
-	fputs("accepted connection!\n", stderr);
-	if (!(conn = fdopen(conn_fd, "r"))) {
-		perror("fdopen(server connection)");
-		exit(EXIT_FAILURE);
-	}
+	for (;;) {
+		len = 0;
 
-	len = fread(msg, 1, sizeof msg, conn);
-	if (len != 6 || memcmp("hello\n", msg, 6)) {
-		if (ferror(conn))
-			perror("fread(server connection)");
-		else
+		fputs("waiting for server connection\n", stderr);
+		if ((conn = accept(listener, nullptr, nullptr)) == -1) {
+			perror("accept");
+			exit(EXIT_FAILURE);
+		}
+		fputs("accepted connection!\n", stderr);
+
+		for (;;) {
+			r = read(conn, msg + len, sizeof msg - len);
+			if (r == -1) {
+				perror("read");
+				exit(EXIT_FAILURE);
+			}
+			if (r == 0)
+				break;
+			len += r;
+		}
+		close(conn);
+
+		if (memcmp("hello\n", msg, len) || len > 6) {
 			fprintf(stderr, "unexpected connection data: %.*s",
 			        (int)len, msg);
-		exit(EXIT_FAILURE);
+			exit(EXIT_FAILURE);
+		}
+
+		// If connection was disconnect partway through, try again.
+		if (len < 6)
+			continue;
+
+		return;
 	}
-	fclose(conn);
 }
 
 static void drain_connections(int listener)

base-commit: 067c6a5d50971242f9cb8ac0ac76e20d88a9b5c1
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] release/checks/integration: handle partial sends
  2025-11-29 18:00 [PATCH v2] release/checks/integration: handle partial sends Alyssa Ross
@ 2025-11-29 20:02 ` Yureka
  2025-11-30 16:08 ` Alyssa Ross
  1 sibling, 0 replies; 3+ messages in thread
From: Yureka @ 2025-11-29 20:02 UTC (permalink / raw)
  To: Alyssa Ross; +Cc: devel


On 11/29/25 19:00, Alyssa Ross wrote:
> Sometimes we see a test failure that looks like this:
>
> 	unexpected connection data: qemu-system-aarch64: terminating on signal 15 from pid 184 ()
>
> I think this is because, now that the nc command in the networking
> integration test has a timeout, it's possible for it to time out after
> having opened the connection, but before having written all its input
> to it.  Therefore, ignore connections that send a prefix of the
> expected data (including nothing), and just wait for the next
> connection rather than failing if that happens.
>
> Closes: https://spectrum-os.org/lists/archives/spectrum-devel/875xbl33vw.fsf@alyssa.is/
> Fixes: c61b297 ("release/checks/integration: add nc timeout")
> Signed-off-by: Alyssa Ross <hi@alyssa.is>
> ---
> v2: close connections when finished reading.
> v1: https://spectrum-os.org/lists/archives/spectrum-devel/20251129163521.717709-2-hi@alyssa.is/
>
>   release/checks/integration/networking.c | 50 +++++++++++++++----------
>   1 file changed, 31 insertions(+), 19 deletions(-)
>
> diff --git a/release/checks/integration/networking.c b/release/checks/integration/networking.c
> index 97d7895..df76ec5 100644
> --- a/release/checks/integration/networking.c
> +++ b/release/checks/integration/networking.c
> @@ -57,32 +57,44 @@ static int setup_server(void)
>   
>   static void expect_connection(int listener)
>   {
> -	int conn_fd;
> -	FILE *conn;
> +	int conn, r;
>   	char msg[7];
>   	size_t len;
>   
> -	fputs("waiting for server connection\n", stderr);
> -	if ((conn_fd = accept(listener, nullptr, nullptr)) == -1) {
> -		perror("accept");
> -		exit(EXIT_FAILURE);
> -	}
> -	fputs("accepted connection!\n", stderr);
> -	if (!(conn = fdopen(conn_fd, "r"))) {
> -		perror("fdopen(server connection)");
> -		exit(EXIT_FAILURE);
> -	}
> +	for (;;) {
> +		len = 0;
>   
> -	len = fread(msg, 1, sizeof msg, conn);
> -	if (len != 6 || memcmp("hello\n", msg, 6)) {
> -		if (ferror(conn))
> -			perror("fread(server connection)");
> -		else
> +		fputs("waiting for server connection\n", stderr);
> +		if ((conn = accept(listener, nullptr, nullptr)) == -1) {
> +			perror("accept");
> +			exit(EXIT_FAILURE);
> +		}
> +		fputs("accepted connection!\n", stderr);
> +
> +		for (;;) {
> +			r = read(conn, msg + len, sizeof msg - len);
> +			if (r == -1) {
> +				perror("read");
> +				exit(EXIT_FAILURE);
> +			}
> +			if (r == 0)
> +				break;
> +			len += r;
> +		}
> +		close(conn);
> +
> +		if (memcmp("hello\n", msg, len) || len > 6) {
>   			fprintf(stderr, "unexpected connection data: %.*s",
>   			        (int)len, msg);
> -		exit(EXIT_FAILURE);
> +			exit(EXIT_FAILURE);
> +		}
> +
> +		// If connection was disconnect partway through, try again.
> +		if (len < 6)
> +			continue;
> +
> +		return;
>   	}
> -	fclose(conn);
>   }
>   
>   static void drain_connections(int listener)
>
> base-commit: 067c6a5d50971242f9cb8ac0ac76e20d88a9b5c1
Reviewed-by: Yureka Lilian <yureka@cyberchaos.dev>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] release/checks/integration: handle partial sends
  2025-11-29 18:00 [PATCH v2] release/checks/integration: handle partial sends Alyssa Ross
  2025-11-29 20:02 ` Yureka
@ 2025-11-30 16:08 ` Alyssa Ross
  1 sibling, 0 replies; 3+ messages in thread
From: Alyssa Ross @ 2025-11-30 16:08 UTC (permalink / raw)
  To: Alyssa Ross, devel; +Cc: Demi Marie Obenour, Yureka Lilian

This patch has been committed as d0dba15c869b52ae49dfb94a7195c3e7b2c972df,
which can be viewed online at
https://spectrum-os.org/git/spectrum/commit/?id=d0dba15c869b52ae49dfb94a7195c3e7b2c972df.

This is an automated message.  Send comments/questions/requests to:
Alyssa Ross <hi@alyssa.is>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-30 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29 18:00 [PATCH v2] release/checks/integration: handle partial sends Alyssa Ross
2025-11-29 20:02 ` Yureka
2025-11-30 16:08 ` Alyssa Ross

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).