* [PATCH net-next 0/2] vsock/test: improve sigpipe test reliability @ 2025-05-08 14:20 Stefano Garzarella 2025-05-08 14:20 ` [PATCH net-next 1/2] vsock/test: retry send() to avoid occasional failure in sigpipe test Stefano Garzarella 2025-05-08 14:20 ` [PATCH net-next 2/2] vsock/test: check also expected errno on " Stefano Garzarella 0 siblings, 2 replies; 7+ messages in thread From: Stefano Garzarella @ 2025-05-08 14:20 UTC (permalink / raw) To: netdev; +Cc: linux-kernel, Stefano Garzarella, virtualization Running the tests continuously I noticed that sometimes the sigpipe test would fail due to a race between the control message of the test and the vsock transport messages. While I was at it I also improved the test by checking the errno we expect. Stefano Garzarella (2): vsock/test: retry send() to avoid occasional failure in sigpipe test vsock/test: check also expected errno on sigpipe test tools/testing/vsock/vsock_test.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) -- 2.49.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next 1/2] vsock/test: retry send() to avoid occasional failure in sigpipe test 2025-05-08 14:20 [PATCH net-next 0/2] vsock/test: improve sigpipe test reliability Stefano Garzarella @ 2025-05-08 14:20 ` Stefano Garzarella 2025-05-13 10:37 ` Paolo Abeni 2025-05-08 14:20 ` [PATCH net-next 2/2] vsock/test: check also expected errno on " Stefano Garzarella 1 sibling, 1 reply; 7+ messages in thread From: Stefano Garzarella @ 2025-05-08 14:20 UTC (permalink / raw) To: netdev; +Cc: linux-kernel, Stefano Garzarella, virtualization From: Stefano Garzarella <sgarzare@redhat.com> When the other peer calls shutdown(SHUT_RD), there is a chance that the send() call could occur before the message carrying the close information arrives over the transport. In such cases, the send() might still succeed. To avoid this race, let's retry the send() call a few times, ensuring the test is more reliable. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> --- tools/testing/vsock/vsock_test.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index d0f6d253ac72..7de870dee1cf 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1064,11 +1064,18 @@ 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); - } + /* When the other peer calls shutdown(SHUT_RD), there is a chance that + * the send() call could occur before the message carrying the close + * information arrives over the transport. In such cases, the send() + * might still succeed. To avoid this race, let's retry the send() call + * a few times, ensuring the test is more reliable. + */ + timeout_begin(TIMEOUT); + do { + res = send(fd, "A", 1, 0); + timeout_check("send"); + } while (res != -1); + timeout_end(); if (!have_sigpipe) { fprintf(stderr, "SIGPIPE expected\n"); @@ -1077,11 +1084,12 @@ 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); - } + timeout_begin(TIMEOUT); + do { + res = send(fd, "A", 1, MSG_NOSIGNAL); + timeout_check("send"); + } while (res != -1); + timeout_end(); if (have_sigpipe) { fprintf(stderr, "SIGPIPE not expected\n"); -- 2.49.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 1/2] vsock/test: retry send() to avoid occasional failure in sigpipe test 2025-05-08 14:20 ` [PATCH net-next 1/2] vsock/test: retry send() to avoid occasional failure in sigpipe test Stefano Garzarella @ 2025-05-13 10:37 ` Paolo Abeni 2025-05-13 13:46 ` Stefano Garzarella 0 siblings, 1 reply; 7+ messages in thread From: Paolo Abeni @ 2025-05-13 10:37 UTC (permalink / raw) To: Stefano Garzarella, netdev; +Cc: linux-kernel, virtualization On 5/8/25 4:20 PM, Stefano Garzarella wrote: > From: Stefano Garzarella <sgarzare@redhat.com> > > When the other peer calls shutdown(SHUT_RD), there is a chance that > the send() call could occur before the message carrying the close > information arrives over the transport. In such cases, the send() > might still succeed. To avoid this race, let's retry the send() call > a few times, ensuring the test is more reliable. > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> > --- > tools/testing/vsock/vsock_test.c | 28 ++++++++++++++++++---------- > 1 file changed, 18 insertions(+), 10 deletions(-) > > diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c > index d0f6d253ac72..7de870dee1cf 100644 > --- a/tools/testing/vsock/vsock_test.c > +++ b/tools/testing/vsock/vsock_test.c > @@ -1064,11 +1064,18 @@ 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); > - } > + /* When the other peer calls shutdown(SHUT_RD), there is a chance that > + * the send() call could occur before the message carrying the close > + * information arrives over the transport. In such cases, the send() > + * might still succeed. To avoid this race, let's retry the send() call > + * a few times, ensuring the test is more reliable. > + */ > + timeout_begin(TIMEOUT); > + do { > + res = send(fd, "A", 1, 0); > + timeout_check("send"); > + } while (res != -1); AFAICS the above could spin on send() for up to 10s, I would say considerably more than 'a few times' ;) In practice that could cause side effect on the timing of other concurrent tests (due to one CPU being 100% used for a while). What if the peer rcvbuf fills-up: will the send fail? That could cause false-negative. I *think* it should be better to insert a short sleep in the loop. /P ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 1/2] vsock/test: retry send() to avoid occasional failure in sigpipe test 2025-05-13 10:37 ` Paolo Abeni @ 2025-05-13 13:46 ` Stefano Garzarella 0 siblings, 0 replies; 7+ messages in thread From: Stefano Garzarella @ 2025-05-13 13:46 UTC (permalink / raw) To: Paolo Abeni; +Cc: netdev, linux-kernel, virtualization On Tue, May 13, 2025 at 12:37:36PM +0200, Paolo Abeni wrote: >On 5/8/25 4:20 PM, Stefano Garzarella wrote: >> From: Stefano Garzarella <sgarzare@redhat.com> >> >> When the other peer calls shutdown(SHUT_RD), there is a chance that >> the send() call could occur before the message carrying the close >> information arrives over the transport. In such cases, the send() >> might still succeed. To avoid this race, let's retry the send() call >> a few times, ensuring the test is more reliable. >> >> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> >> --- >> tools/testing/vsock/vsock_test.c | 28 ++++++++++++++++++---------- >> 1 file changed, 18 insertions(+), 10 deletions(-) >> >> diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c >> index d0f6d253ac72..7de870dee1cf 100644 >> --- a/tools/testing/vsock/vsock_test.c >> +++ b/tools/testing/vsock/vsock_test.c >> @@ -1064,11 +1064,18 @@ 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); >> - } >> + /* When the other peer calls shutdown(SHUT_RD), there is a chance that >> + * the send() call could occur before the message carrying the close >> + * information arrives over the transport. In such cases, the send() >> + * might still succeed. To avoid this race, let's retry the send() call >> + * a few times, ensuring the test is more reliable. >> + */ >> + timeout_begin(TIMEOUT); >> + do { >> + res = send(fd, "A", 1, 0); >> + timeout_check("send"); >> + } while (res != -1); > >AFAICS the above could spin on send() for up to 10s, I would say >considerably more than 'a few times' ;) > >In practice that could cause side effect on the timing of other >concurrent tests (due to one CPU being 100% used for a while). > >What if the peer rcvbuf fills-up: will the send fail? That could cause >false-negative. Good point! > >I *think* it should be better to insert a short sleep in the loop. Agree, I'll add. Thanks, Stefano ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next 2/2] vsock/test: check also expected errno on sigpipe test 2025-05-08 14:20 [PATCH net-next 0/2] vsock/test: improve sigpipe test reliability Stefano Garzarella 2025-05-08 14:20 ` [PATCH net-next 1/2] vsock/test: retry send() to avoid occasional failure in sigpipe test Stefano Garzarella @ 2025-05-08 14:20 ` Stefano Garzarella 2025-05-13 10:41 ` Paolo Abeni 1 sibling, 1 reply; 7+ messages in thread From: Stefano Garzarella @ 2025-05-08 14:20 UTC (permalink / raw) To: netdev; +Cc: linux-kernel, Stefano Garzarella, virtualization From: Stefano Garzarella <sgarzare@redhat.com> In the sigpipe test, we expect send() to fail, but we do not check if send() fails with the errno we expect (EPIPE). Add this check and repeat the send() in case of EINTR as we do in other tests. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> --- tools/testing/vsock/vsock_test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 7de870dee1cf..533d9463a297 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1074,9 +1074,13 @@ static void test_stream_check_sigpipe(int fd) do { res = send(fd, "A", 1, 0); timeout_check("send"); - } while (res != -1); + } while (res != -1 && errno == EINTR); timeout_end(); + if (errno != EPIPE) { + fprintf(stderr, "unexpected send(2) errno %d\n", errno); + exit(EXIT_FAILURE); + } if (!have_sigpipe) { fprintf(stderr, "SIGPIPE expected\n"); exit(EXIT_FAILURE); @@ -1088,9 +1092,13 @@ static void test_stream_check_sigpipe(int fd) do { res = send(fd, "A", 1, MSG_NOSIGNAL); timeout_check("send"); - } while (res != -1); + } while (res != -1 && errno == EINTR); timeout_end(); + if (errno != EPIPE) { + fprintf(stderr, "unexpected send(2) errno %d\n", errno); + exit(EXIT_FAILURE); + } if (have_sigpipe) { fprintf(stderr, "SIGPIPE not expected\n"); exit(EXIT_FAILURE); -- 2.49.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 2/2] vsock/test: check also expected errno on sigpipe test 2025-05-08 14:20 ` [PATCH net-next 2/2] vsock/test: check also expected errno on " Stefano Garzarella @ 2025-05-13 10:41 ` Paolo Abeni 2025-05-13 13:49 ` Stefano Garzarella 0 siblings, 1 reply; 7+ messages in thread From: Paolo Abeni @ 2025-05-13 10:41 UTC (permalink / raw) To: Stefano Garzarella, netdev; +Cc: linux-kernel, virtualization On 5/8/25 4:20 PM, Stefano Garzarella wrote: > diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c > index 7de870dee1cf..533d9463a297 100644 > --- a/tools/testing/vsock/vsock_test.c > +++ b/tools/testing/vsock/vsock_test.c > @@ -1074,9 +1074,13 @@ static void test_stream_check_sigpipe(int fd) > do { > res = send(fd, "A", 1, 0); > timeout_check("send"); > - } while (res != -1); > + } while (res != -1 && errno == EINTR); I'm low on coffee, but should the above condition be: res != -1 || errno == EINTR instead? Same thing below. /P ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 2/2] vsock/test: check also expected errno on sigpipe test 2025-05-13 10:41 ` Paolo Abeni @ 2025-05-13 13:49 ` Stefano Garzarella 0 siblings, 0 replies; 7+ messages in thread From: Stefano Garzarella @ 2025-05-13 13:49 UTC (permalink / raw) To: Paolo Abeni; +Cc: netdev, linux-kernel, virtualization On Tue, May 13, 2025 at 12:41:17PM +0200, Paolo Abeni wrote: >On 5/8/25 4:20 PM, Stefano Garzarella wrote: >> diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c >> index 7de870dee1cf..533d9463a297 100644 >> --- a/tools/testing/vsock/vsock_test.c >> +++ b/tools/testing/vsock/vsock_test.c >> @@ -1074,9 +1074,13 @@ static void test_stream_check_sigpipe(int fd) >> do { >> res = send(fd, "A", 1, 0); >> timeout_check("send"); >> - } while (res != -1); >> + } while (res != -1 && errno == EINTR); > >I'm low on coffee, but should the above condition be: > > res != -1 || errno == EINTR > >instead? Ooops, copy & paste where we waited successful send(). > >Same thing below. I'll fix both! Thanks, Stefano ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-05-13 13:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-05-08 14:20 [PATCH net-next 0/2] vsock/test: improve sigpipe test reliability Stefano Garzarella 2025-05-08 14:20 ` [PATCH net-next 1/2] vsock/test: retry send() to avoid occasional failure in sigpipe test Stefano Garzarella 2025-05-13 10:37 ` Paolo Abeni 2025-05-13 13:46 ` Stefano Garzarella 2025-05-08 14:20 ` [PATCH net-next 2/2] vsock/test: check also expected errno on " Stefano Garzarella 2025-05-13 10:41 ` Paolo Abeni 2025-05-13 13:49 ` Stefano Garzarella
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®