The current 'tipc_wait_for_connect()' function makes a loop and waits for the condition 'sk->sk_state != TIPC_CONNECTING' to conclude if the connecting has done. However, when the condition is met, it always returns '0' even in the case the connecting was actually failed (e.g. refused because the server socket has closed...) and the socket state was set to 'TIPC_DISCONNECTING'. This results in a wrong return code for the 'connect()' call from user, making it believe that the connection is established and goes ahead with more actions e.g. building & sending a message but then finally gets an unexpected result (e.g. '-EPIPE').
This commit fixes the issue by instead setting the wait condition to 'tipc_sk_connected(sk)', so that the function will return '0' only when the connection is really established. Otherwise, either the socket error code if any or '-ETIMEDOUT'/'-EINTR' will be returned correspondingly. --------- v2: changed after discussing with Ying --------- Signed-off-by: Tuong Lien <tuong.t.l...@dektech.com.au> --- net/tipc/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 6552f986774c..2f5679f84060 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2432,8 +2432,8 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) return sock_intr_errno(*timeo_p); add_wait_queue(sk_sleep(sk), &wait); - done = sk_wait_event(sk, timeo_p, - sk->sk_state != TIPC_CONNECTING, &wait); + done = sk_wait_event(sk, timeo_p, tipc_sk_connected(sk), + &wait); remove_wait_queue(sk_sleep(sk), &wait); } while (!done); return 0; -- 2.13.7 _______________________________________________ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion