* [PATCH net] vsock/test: Fix occasional failure in SOCK_STREAM SHUT_RD test
@ 2025-05-26 4:32 Konstantin Shkolnyy
2025-05-26 7:54 ` Stefano Garzarella
0 siblings, 1 reply; 2+ messages in thread
From: Konstantin Shkolnyy @ 2025-05-26 4:32 UTC (permalink / raw)
To: sgarzare
Cc: virtualization, netdev, linux-kernel, mjrosato,
Konstantin Shkolnyy
The test outputs:
"SOCK_STREAM SHUT_RD...expected send(2) failure, got 1".
It tests that shutdown(fd, SHUT_RD) on one side causes send() to fail on
the other side. However, sometimes there is a delay in delivery of the
SHUT_RD command, send() succeeds and the test fails, even though the
command is properly delivered and send() starts failing several
milliseconds later.
The delay occurs in the kernel because the used buffer notification
callback virtio_vsock_rx_done(), called upon receipt of the SHUT_RD
command, doesn't immediately disable send(). It delegates that to
a kernel thread (via vsock->rx_work). Sometimes that thread is delayed
more than the test expects.
Change the test to keep calling send() until it fails or a timeout occurs.
Fixes: b698bd97c5711 ("test/vsock: shutdowned socket test")
Signed-off-by: Konstantin Shkolnyy <kshk@linux.ibm.com>
---
tools/testing/vsock/vsock_test.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index 613551132a96..c3b90a94a281 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -1058,17 +1058,22 @@ static void sigpipe(int signo)
have_sigpipe = 1;
}
-static void test_stream_check_sigpipe(int fd)
+static void test_for_send_failure(int fd, int send_flags)
{
- ssize_t res;
+ timeout_begin(TIMEOUT);
+ while (true) {
+ if (send(fd, "A", 1, send_flags) == -1)
+ return;
+ timeout_check("expected send(2) failure");
+ }
+ timeout_end();
+}
+static void test_stream_check_sigpipe(int fd)
+{
have_sigpipe = 0;
- res = send(fd, "A", 1, 0);
- if (res != -1) {
- fprintf(stderr, "expected send(2) failure, got %zi\n", res);
- exit(EXIT_FAILURE);
- }
+ test_for_send_failure(fd, 0);
if (!have_sigpipe) {
fprintf(stderr, "SIGPIPE expected\n");
@@ -1077,11 +1082,7 @@ static void test_stream_check_sigpipe(int fd)
have_sigpipe = 0;
- res = send(fd, "A", 1, MSG_NOSIGNAL);
- if (res != -1) {
- fprintf(stderr, "expected send(2) failure, got %zi\n", res);
- exit(EXIT_FAILURE);
- }
+ test_for_send_failure(fd, MSG_NOSIGNAL);
if (have_sigpipe) {
fprintf(stderr, "SIGPIPE not expected\n");
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] vsock/test: Fix occasional failure in SOCK_STREAM SHUT_RD test
2025-05-26 4:32 [PATCH net] vsock/test: Fix occasional failure in SOCK_STREAM SHUT_RD test Konstantin Shkolnyy
@ 2025-05-26 7:54 ` Stefano Garzarella
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Garzarella @ 2025-05-26 7:54 UTC (permalink / raw)
To: Konstantin Shkolnyy; +Cc: virtualization, netdev, linux-kernel, mjrosato
On Sun, May 25, 2025 at 11:32:20PM -0500, Konstantin Shkolnyy wrote:
>The test outputs:
>"SOCK_STREAM SHUT_RD...expected send(2) failure, got 1".
>
>It tests that shutdown(fd, SHUT_RD) on one side causes send() to fail on
>the other side. However, sometimes there is a delay in delivery of the
>SHUT_RD command, send() succeeds and the test fails, even though the
>command is properly delivered and send() starts failing several
>milliseconds later.
>
>The delay occurs in the kernel because the used buffer notification
>callback virtio_vsock_rx_done(), called upon receipt of the SHUT_RD
>command, doesn't immediately disable send(). It delegates that to
>a kernel thread (via vsock->rx_work). Sometimes that thread is delayed
>more than the test expects.
>
>Change the test to keep calling send() until it fails or a timeout occurs.
>
>Fixes: b698bd97c5711 ("test/vsock: shutdowned socket test")
>Signed-off-by: Konstantin Shkolnyy <kshk@linux.ibm.com>
>---
> tools/testing/vsock/vsock_test.c | 25 +++++++++++++------------
> 1 file changed, 13 insertions(+), 12 deletions(-)
>
>diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
>index 613551132a96..c3b90a94a281 100644
>--- a/tools/testing/vsock/vsock_test.c
>+++ b/tools/testing/vsock/vsock_test.c
>@@ -1058,17 +1058,22 @@ static void sigpipe(int signo)
> have_sigpipe = 1;
> }
>
>-static void test_stream_check_sigpipe(int fd)
>+static void test_for_send_failure(int fd, int send_flags)
> {
>- ssize_t res;
>+ timeout_begin(TIMEOUT);
>+ while (true) {
>+ if (send(fd, "A", 1, send_flags) == -1)
>+ return;
>+ timeout_check("expected send(2) failure");
>+ }
>+ timeout_end();
>+}
I'd move this in util.c like we did in
https://lore.kernel.org/virtualization/20250522-vsock-linger-v6-3-2ad00b0e447e@rbox.co/
And I'd rename following the other functions we have there.
Thanks,
Stefano
>
>+static void test_stream_check_sigpipe(int fd)
>+{
> have_sigpipe = 0;
>
>- res = send(fd, "A", 1, 0);
>- if (res != -1) {
>- fprintf(stderr, "expected send(2) failure, got %zi\n", res);
>- exit(EXIT_FAILURE);
>- }
>+ test_for_send_failure(fd, 0);
>
> if (!have_sigpipe) {
> fprintf(stderr, "SIGPIPE expected\n");
>@@ -1077,11 +1082,7 @@ static void test_stream_check_sigpipe(int fd)
>
> have_sigpipe = 0;
>
>- res = send(fd, "A", 1, MSG_NOSIGNAL);
>- if (res != -1) {
>- fprintf(stderr, "expected send(2) failure, got %zi\n", res);
>- exit(EXIT_FAILURE);
>- }
>+ test_for_send_failure(fd, MSG_NOSIGNAL);
>
> if (have_sigpipe) {
> fprintf(stderr, "SIGPIPE not expected\n");
>--
>2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-26 7:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-26 4:32 [PATCH net] vsock/test: Fix occasional failure in SOCK_STREAM SHUT_RD test Konstantin Shkolnyy
2025-05-26 7:54 ` Stefano Garzarella
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).