char-socket: disable reconnect timer in the sync connect
PATCH 1/1 char-socket: disable reconnect timer in the sync connect
From: suruifeng <[email protected]>
The qio_channel_socket_connect_sync maybe called twice if the openvswitchd restart during we attaching a vhost-user nic.
-> call trace 1:
net_vhost_user_init
tcp_chr_wait_connected //loop call sync connect until socekt connected
tcp_chr_connect_client_sync //return, but socekt state still disconnected
qio_channel_socket_connect_sync //socket connect sucess
tcp_chr_new_client
tcp_chr_connect
qemu_chr_be_event
net_vhost_user_event //CHR_EVENT_OPENED
vhost_user_start
tcp_chr_write //Broken Pipe, as peer restart
tcp_chr_disconnect_locked //disconnect & reconnect timer create
-> call trace 2:
socket_reconnect_timeout //timeout, and the peer restart just finished
tcp_chr_connect_client_async //concurrent with tcp_chr_connect_client_sync
tcp_chr_connect_client_task
qio_channel_socket_connect_sync //try connect same socket
This patch disabled tcp reconnect timer when we try to connect in synchronous mode, it seems to work.
chardev/char-socket.c +12 -1
@@ -80,6 +80,7 @@ struct SocketChardev {bool is_websock; +bool async_reconnect_disable;GSource *reconnect_timer;int64_t reconnect_time;bool connect_err_reported;
@@ -506,7 +507,9 @@ static void tcp_chr_disconnect_locked(Chardev *chr)if (emit_close) {qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); } -if (s->reconnect_time && !s->reconnect_timer) { +if (s->reconnect_time && + !s->reconnect_timer && + !s->async_reconnect_disable) {qemu_chr_socket_restart_timer (chr); } }
@@ -954,15 +957,23 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp) {SocketChardev *s =SOCKET_CHARDEV (chr);QIOChannelSocket *sioc =qio_channel_socket_new (); + + s->async_reconnect_disable = true;tcp_chr_change_state (s,TCP_CHARDEV_STATE_CONNECTING );tcp_chr_set_client_ioc_name (chr, sioc);if (qio_channel_socket_connect_sync (sioc, s->addr, errp) <0 ) {tcp_chr_change_state (s,TCP_CHARDEV_STATE_DISCONNECTED );object_unref (OBJECT (sioc)); + s->async_reconnect_disable = false;return -1 ; }tcp_chr_new_client (chr, sioc);object_unref (OBJECT (sioc)); + s->async_reconnect_disable = false; + +if (s->state !=TCP_CHARDEV_STATE_CONNECTED ) { +return -1 ; + }return 0 ; }
Signature · 1 line
2.26.0.windows.1
Hi
Quoted 20 lines · Wang Xin
From: suruifeng <[email protected]>
The
qio_channel_socket_connect_syncmaybe called twice if the openvswitchd restart during we attaching a vhost-user nic.-> call trace 1:
net_vhost_user_init
tcp_chr_wait_connected//loop call sync connect until socekt connected
tcp_chr_connect_client_sync//return, but socekt state still
disconnected
qio_channel_socket_connect_sync//socket connect sucess
tcp_chr_new_client
tcp_chr_connect
qemu_chr_be_event
net_vhost_user_event//CHR_EVENT_OPENED
vhost_user_start
tcp_chr_write//Broken Pipe, as peer restart
tcp_chr_disconnect_locked//disconnect & reconnect
timer create
Quoted 5 lines
-> call trace 2:
socket_reconnect_timeout//timeout, and the peer restart just finished
tcp_chr_connect_client_async//concurrent withtcp_chr_connect_client_sync
What do you mean by "concurrent with tcp_chr_connect_client_sync"? Are we talking about threads? If not, could you provide the full backtrace?
tcp_chr_connect_client_task
Quoted 1 line
qio_channel_socket_connect_sync//try connect same socket
This patch disabled tcp reconnect timer when we try to connect in
Quoted 2 lines
synchronous mode,
it seems to work.
Quoted 28 lines
Signed-off-by suruifeng <[email protected]>Signed-off-by Wang Xin <[email protected]>chardev/char-socket.c +4
-1@@ -80,6 +80,7 @@ struct SocketChardev {bool is_websock; +bool async_reconnect_disable;GSource *reconnect_timer;int64_t reconnect_time;bool connect_err_reported;@@ -506,7 +507,9 @@ static void tcp_chr_disconnect_locked(Chardev *chr)if (emit_close) {qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); } -if (s->reconnect_time && !s->reconnect_timer) { +if (s->reconnect_time && + !s->reconnect_timer && + !s->async_reconnect_disable) {qemu_chr_socket_restart_timer (chr); } }
chardev/char-socket.c static int tcp_chr_connect_client_sync(Chardev *chr, · line 963
Quoted 7 lines
chardev/char-socket.c +2
-0@@ -954,15 +957,23 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp) {SocketChardev *s =SOCKET_CHARDEV (chr);QIOChannelSocket *sioc =qio_channel_socket_new (); + + s->async_reconnect_disable = true;
Instead of having a new field, we could probably zero s->reconnect_timer temporarily.
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
Quoted 5 lines
chardev/char-socket.c +1
-0tcp_chr_set_client_ioc_name (chr, sioc);if (qio_channel_socket_connect_sync (sioc, s->addr, errp) <0 ) {tcp_chr_change_state (s,TCP_CHARDEV_STATE_DISCONNECTED );object_unref (OBJECT (sioc)); + s->async_reconnect_disable = false;
chardev/char-socket.c static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp) · line 979
Quoted 10 lines
chardev/char-socket.c +5
-0return -1 ; }tcp_chr_new_client (chr, sioc);object_unref (OBJECT (sioc)); + s->async_reconnect_disable = false; + +if (s->state !=TCP_CHARDEV_STATE_CONNECTED ) { +return -1 ; + }
How is this related?
return 0;
Quoted 6 lines
chardev/char-socket.c +0
-1} --2.26.0.windows.1