[Qemu-devel] [PATCH] tests/test-filter-redirector: move close()

Klim Kireev posted 1 patch 6 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180201134831.17709-1-klim.kireev@virtuozzo.com
Test checkpatch passed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test docker-quick@centos6 passed
Test ppc passed
Test s390x passed
tests/test-filter-redirector.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH] tests/test-filter-redirector: move close()
Posted by Klim Kireev 6 years, 2 months ago
Since we have separate handler on POLLHUP, which drops data
after closing the connection we need to fix this test, because
it sends data and instantly close the socket creating race condition.
In some cases on other end of socket client closes it faster than
reads data. To prevent it I suggest to close socket after recieving.

Signed-off-by: Klim Kireev <klim.kireev@virtuozzo.com>
---
 tests/test-filter-redirector.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test-filter-redirector.c b/tests/test-filter-redirector.c
index f2566144cf..fbaf19bbd8 100644
--- a/tests/test-filter-redirector.c
+++ b/tests/test-filter-redirector.c
@@ -186,7 +186,6 @@ static void test_redirector_rx(void)
 
     ret = iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf));
     g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
-    close(send_sock);
 
     ret = qemu_recv(backend_sock[0], &len, sizeof(len), 0);
     g_assert_cmpint(ret, ==, sizeof(len));
@@ -197,6 +196,7 @@ static void test_redirector_rx(void)
     ret = qemu_recv(backend_sock[0], recv_buf, len, 0);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
+    close(send_sock);
     g_free(recv_buf);
     unlink(sock_path0);
     unlink(sock_path1);
-- 
2.14.3


Re: [Qemu-devel] [PATCH] tests/test-filter-redirector: move close()
Posted by Paolo Bonzini 6 years, 2 months ago
On 01/02/2018 08:48, Klim Kireev wrote:
> Since we have separate handler on POLLHUP, which drops data
> after closing the connection we need to fix this test, because
> it sends data and instantly close the socket creating race condition.
> In some cases on other end of socket client closes it faster than
> reads data. To prevent it I suggest to close socket after recieving.
> 
> Signed-off-by: Klim Kireev <klim.kireev@virtuozzo.com>
> ---
>  tests/test-filter-redirector.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/test-filter-redirector.c b/tests/test-filter-redirector.c
> index f2566144cf..fbaf19bbd8 100644
> --- a/tests/test-filter-redirector.c
> +++ b/tests/test-filter-redirector.c
> @@ -186,7 +186,6 @@ static void test_redirector_rx(void)
>  
>      ret = iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf));
>      g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
> -    close(send_sock);
>  
>      ret = qemu_recv(backend_sock[0], &len, sizeof(len), 0);
>      g_assert_cmpint(ret, ==, sizeof(len));
> @@ -197,6 +196,7 @@ static void test_redirector_rx(void)
>      ret = qemu_recv(backend_sock[0], recv_buf, len, 0);
>      g_assert_cmpstr(recv_buf, ==, send_buf);
>  
> +    close(send_sock);
>      g_free(recv_buf);
>      unlink(sock_path0);
>      unlink(sock_path1);
> 

Queued, thanks.

Paolo