From nobody Fri Nov 14 12:16:54 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1588066769; cv=none; d=zohomail.com; s=zohoarc; b=Y94tmlOmFwbpxtE1dm5odlPF2aZdRv55ES8xdvgDRGyll8HjSxUziAIsLxN7YH+9JtHtOeVwgPCDRncNooO60XwL98PBvOu6lH0DZnZe8LvECOoA3P53w5dP39mLQfDzLdyq0ZqbUgemu7q3Bk3Y5ybZ+6wHLxvhXbyyA5dHF5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588066769; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=YVaXGPGd8Q2+faJKdiZOSxUYLEVCJh2RPvbe2ldUqVs=; b=S9BVBtE+WXOJyWqNrE3cqGd/gd2yzwopxoWI5zEPeFBF6PPPNip0fqdKIPv84hRgZTuFtXUvanwuV75kKQhZ73Adicf1VOk/VVqbab0I4zuvcCLmlb4RB+KSXIXkfIffFyB+aDOAL0oFYobEZ3J3AwhvBpLTgTlr6RTSeTHWc68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588066769854483.4114676109082; Tue, 28 Apr 2020 02:39:29 -0700 (PDT) Received: from localhost ([::1]:49872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTMi4-0001WT-TL for importer@patchew.org; Tue, 28 Apr 2020 05:39:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33992) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTMYy-0007Em-F5 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 05:31:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTMXB-0008PT-Ii for qemu-devel@nongnu.org; Tue, 28 Apr 2020 05:29:59 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTLxv-0007Iv-Q9 for qemu-devel@nongnu.org; Tue, 28 Apr 2020 04:51:44 -0400 Received: by mail-pf1-x443.google.com with SMTP id d184so10367709pfd.4 for ; Tue, 28 Apr 2020 01:51:42 -0700 (PDT) Received: from 31_216.localdomain ([47.75.194.237]) by smtp.gmail.com with ESMTPSA id k4sm10502932pgg.88.2020.04.28.01.51.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2020 01:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YVaXGPGd8Q2+faJKdiZOSxUYLEVCJh2RPvbe2ldUqVs=; b=LzsWTNS6enY0henXY+D+4tLpPLoCZfSR90wWPbRIRQa+87NMUqkvfLVNAz8YdhOvto 4c2gmCYVbLKUNyPIYvA6wdfAtSBYsabEJ9g+Fzjk71nmEpQcz9iqYGgJP2DkJieSEcGD ZXe4qLfnCzV/HtbIkCW+I84efOl3ID2xm4vtFCgm/n9Us2S6XSvoXwz4M11iiHjNkPP/ MIw060wLn+G6q7jrrcxH79MBPNDMuwbswnAb0K03XEGCHJOYltxJnHgm6YXu9qJ3aCco nI0WjXoIN51E++Dl+nAdo6p4sYPIcraS/unbV7dApDPce1JJuZ3b6hY+/tjjTX/q2U+M B5fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YVaXGPGd8Q2+faJKdiZOSxUYLEVCJh2RPvbe2ldUqVs=; b=h6ySa+xipM9TQSxm8C+Iaorw02HEcvyKX1qbw/q62rxDeQ3fS6bIWEb7DO6/zDN3ZE 7gg1fKhyt0j1n66BUas5YUgWk0/YguCyz2CwfqwjbohMYZRcDHx9iyKze+pcTrp3oZOV 81YAGpYDUuAbSIj1MRDYyHu/0qsrw6i0HsEOs+TZqH2xCISCx8ee81wvfoI3CuJipQc1 QA5o14LiNsWqMG8TAyT6Pn52dzOTjDUnE3WMiXaOijHfiVy7bL30mSWV4OZ6aLRp/7Dn 9C3nt/SZINNZrEKN355SH3HoUfoP/orHPQqQ420JE0kYTkiGk5NNfn/S4gSjyp3o0Fvu UVWw== X-Gm-Message-State: AGi0Pua3KiHRoDxLUkpjNrUrdwJINgYUTCGFq5SI/clVd5GSH22ROcti IJpFWdcC7nbQWHLrk+KKs9Oigw== X-Google-Smtp-Source: APiQypL4pFfltLhkobmFcVCNvVENvE3oA9Jl4Cf0/t648eXukIjHwoC93pk6DjTZlXZbVTMW7ffqdw== X-Received: by 2002:a62:1c97:: with SMTP id c145mr30019101pfc.68.1588063901508; Tue, 28 Apr 2020 01:51:41 -0700 (PDT) From: Li Feng To: kyle@smartx.com, lifeng1519@gmail.com, dimastep@yandex-team.ru, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH v2] char-socket: initialize reconnect timer only when the timer doesn't start Date: Tue, 28 Apr 2020 16:51:21 +0800 Message-Id: <20200428085122.1621-1-fengli@smartx.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200415032826.16701-4-fengli@smartx.com> References: <20200415032826.16701-4-fengli@smartx.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::443; envelope-from=fengli@smartx.com; helo=mail-pf1-x443.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2607:f8b0:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Feng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @smartx-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When the disconnect event is triggered in the connecting stage, the tcp_chr_disconnect_locked may be called twice. The first call: #0 qemu_chr_socket_restart_timer (chr=3D0x55555582ee90) at chardev/cha= r-socket.c:120 #1 0x000055555558e38c in tcp_chr_disconnect_locked (chr=3D) at chardev/char-socket.c:490 #2 0x000055555558e3cd in tcp_chr_disconnect (chr=3D0x55555582ee90) at = chardev/char-socket.c:497 #3 0x000055555558ea32 in tcp_chr_new_client (chr=3Dchr@entry=3D0x55555= 582ee90, sioc=3Dsioc@entry=3D0x55555582f0b0) at chardev/char-socket.c:892 #4 0x000055555558eeb8 in qemu_chr_socket_connected (task=3D0x55555582f= 300, opaque=3D) at chardev/char-socket.c:1090 #5 0x0000555555574352 in qio_task_complete (task=3Dtask@entry=3D0x5555= 5582f300) at io/task.c:196 #6 0x00005555555745f4 in qio_task_thread_result (opaque=3D0x55555582f3= 00) at io/task.c:111 #7 qio_task_wait_thread (task=3D0x55555582f300) at io/task.c:190 #8 0x000055555558f17e in tcp_chr_wait_connected (chr=3D0x55555582ee90,= errp=3D0x555555802a08 ) at chardev/char-socket.c:1013 #9 0x0000555555567cbd in char_socket_client_reconnect_test (opaque=3D0= x5555557fe020 ) at tests/test-char.c:1152 The second call: #0 0x00007ffff5ac3277 in raise () from /lib64/libc.so.6 #1 0x00007ffff5ac4968 in abort () from /lib64/libc.so.6 #2 0x00007ffff5abc096 in __assert_fail_base () from /lib64/libc.so.6 #3 0x00007ffff5abc142 in __assert_fail () from /lib64/libc.so.6 #4 0x000055555558d10a in qemu_chr_socket_restart_timer (chr=3D0x555555= 82ee90) at chardev/char-socket.c:125 #5 0x000055555558df0c in tcp_chr_disconnect_locked (chr=3D) at chardev/char-socket.c:490 #6 0x000055555558df4d in tcp_chr_disconnect (chr=3D0x55555582ee90) at = chardev/char-socket.c:497 #7 0x000055555558e5b2 in tcp_chr_new_client (chr=3Dchr@entry=3D0x55555= 582ee90, sioc=3Dsioc@entry=3D0x55555582f0b0) at chardev/char-socket.c:892 #8 0x000055555558e93a in tcp_chr_connect_client_sync (chr=3Dchr@entry= =3D0x55555582ee90, errp=3Derrp@entry=3D0x7fffffffd178) at chardev/char-sock= et.c:944 #9 0x000055555558ec78 in tcp_chr_wait_connected (chr=3D0x55555582ee90,= errp=3D0x555555802a08 ) at chardev/char-socket.c:1035 #10 0x000055555556804b in char_socket_client_test (opaque=3D0x5555557fe= 020 ) at tests/test-char.c:1023 Run test/test-char to reproduce this issue. test-char: chardev/char-socket.c:125: qemu_chr_socket_restart_timer: Assert= ion `!s->reconnect_timer' failed. Signed-off-by: Li Feng --- v2: - Rewrite the solution. - Add test to reproduce this issue. chardev/char-socket.c | 2 +- tests/test-char.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1f14c2c7c8..d84330b3c9 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -486,7 +486,7 @@ static void tcp_chr_disconnect_locked(Chardev *chr) if (emit_close) { qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } - if (s->reconnect_time) { + if (s->reconnect_time && !s->reconnect_timer) { qemu_chr_socket_restart_timer(chr); } } diff --git a/tests/test-char.c b/tests/test-char.c index 8d39bdc9fa..13dbbfe2a3 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -625,12 +625,14 @@ static void char_udp_test(void) typedef struct { int event; bool got_pong; + CharBackend *be; } CharSocketTestData; =20 =20 #define SOCKET_PING "Hello" #define SOCKET_PONG "World" =20 +typedef void (*char_socket_cb)(void *opaque, QEMUChrEvent event); =20 static void char_socket_event(void *opaque, QEMUChrEvent event) @@ -639,6 +641,23 @@ char_socket_event(void *opaque, QEMUChrEvent event) data->event =3D event; } =20 +static void +char_socket_event_with_error(void *opaque, QEMUChrEvent event) +{ + CharSocketTestData *data =3D opaque; + CharBackend *be =3D data->be; + data->event =3D event; + switch (event) { + case CHR_EVENT_OPENED: + qemu_chr_fe_disconnect(be); + return; + case CHR_EVENT_CLOSED: + return; + default: + return; + } +} + =20 static void char_socket_read(void *opaque, const uint8_t *buf, int size) @@ -783,6 +802,7 @@ static void char_socket_server_test(gconstpointer opaqu= e) =20 reconnect: data.event =3D -1; + data.be =3D &be; qemu_chr_fe_set_handlers(&be, NULL, NULL, char_socket_event, NULL, &data, NULL, true); @@ -869,6 +889,7 @@ typedef struct { const char *reconnect; bool wait_connected; bool fd_pass; + char_socket_cb event_cb; } CharSocketClientTestConfig; =20 static void char_socket_client_dupid_test(gconstpointer opaque) @@ -920,6 +941,7 @@ static void char_socket_client_dupid_test(gconstpointer= opaque) static void char_socket_client_test(gconstpointer opaque) { const CharSocketClientTestConfig *config =3D opaque; + const char_socket_cb event_cb =3D config->event_cb; QIOChannelSocket *ioc; char *optstr; Chardev *chr; @@ -983,8 +1005,9 @@ static void char_socket_client_test(gconstpointer opaq= ue) =20 reconnect: data.event =3D -1; + data.be =3D &be; qemu_chr_fe_set_handlers(&be, NULL, NULL, - char_socket_event, NULL, + event_cb, NULL, &data, NULL, true); if (config->reconnect) { g_assert(data.event =3D=3D -1); @@ -1022,7 +1045,7 @@ static void char_socket_client_test(gconstpointer opa= que) /* Setup a callback to receive the reply to our greeting */ qemu_chr_fe_set_handlers(&be, char_socket_can_read, char_socket_read, - char_socket_event, NULL, + event_cb, NULL, &data, NULL, true); g_assert(data.event =3D=3D CHR_EVENT_OPENED); data.event =3D -1; @@ -1467,19 +1490,22 @@ int main(int argc, char **argv) =20 #define SOCKET_CLIENT_TEST(name, addr) \ static CharSocketClientTestConfig client1 ## name =3D \ - { addr, NULL, false, false }; \ + { addr, NULL, false, false, char_socket_event}; \ static CharSocketClientTestConfig client2 ## name =3D \ - { addr, NULL, true, false }; \ + { addr, NULL, true, false, char_socket_event }; \ static CharSocketClientTestConfig client3 ## name =3D \ - { addr, ",reconnect=3D1", false }; \ + { addr, ",reconnect=3D1", false, false, char_socket_event }; \ static CharSocketClientTestConfig client4 ## name =3D \ - { addr, ",reconnect=3D1", true }; \ + { addr, ",reconnect=3D1", true, false, char_socket_event }; \ static CharSocketClientTestConfig client5 ## name =3D \ - { addr, NULL, false, true }; \ + { addr, NULL, false, true, char_socket_event }; \ static CharSocketClientTestConfig client6 ## name =3D \ - { addr, NULL, true, true }; \ + { addr, NULL, true, true, char_socket_event }; \ static CharSocketClientTestConfig client7 ## name =3D \ - { addr, ",reconnect=3D1", false, false }; \ + { addr, ",reconnect=3D1", false, false, char_socket_event }; \ + static CharSocketClientTestConfig client8 ## name =3D \ + { addr, ",reconnect=3D1", true, false, \ + char_socket_event_with_error }; \ g_test_add_data_func("/char/socket/client/mainloop/" # name, \ &client1 ##name, char_socket_client_test); \ g_test_add_data_func("/char/socket/client/wait-conn/" # name, \ @@ -1493,7 +1519,9 @@ int main(int argc, char **argv) g_test_add_data_func("/char/socket/client/wait-conn-fdpass/" # name, \ &client6 ##name, char_socket_client_test); \ g_test_add_data_func("/char/socket/client/dupid-reconnect/" # name, \ - &client7 ##name, char_socket_client_dupid_test) + &client7 ##name, char_socket_client_dupid_test);\ + g_test_add_data_func("/char/socket/client/reconnect-error/" # name, \ + &client8 ##name, char_socket_client_test) =20 if (has_ipv4) { SOCKET_SERVER_TEST(tcp, &tcpaddr); --=20 2.11.0