ECONNABORTED
installed in two places in the source code of the Linux kernel kernel socket.
According to the errno
man page and /include/asm-generic/errno.h
#define ECONNABORTED 103 /* Software caused connection abort */
the first is in the function that defines syscall accept4
in /net/socket.c .
Corresponding source code
1533 if (upeer_sockaddr) { 1534 if (newsock->ops->getname(newsock, (struct sockaddr *)&address, 1535 &len, 2) < 0) { 1536 err = -ECONNABORTED; 1537 goto out_fd; 1538 } 1539 err = move_addr_to_user((struct sockaddr *)&address, 1540 len, upeer_sockaddr, upeer_addrlen); 1541 if (err < 0) 1542 goto out_fd; 1543 }
The following is an explanation of the logic.
If a peer-to-peer network address from user space is specified and if the new socket does not have a name, set the error value to ECONNABORTED
and go to the out_fd
label.
the second is in the function that defines the inet_stream_connect
symbol in /net/ipv4/af_inet.c .
Corresponding source code
645 648 if (sk->sk_state == TCP_CLOSE) 649 goto sock_error; 662 sock_error: 663 err = sock_error(sk) ? : -ECONNABORTED; 664 sock->state = SS_UNCONNECTED; 665 if (sk->sk_prot->disconnect(sk, flags)) 666 sock->state = SS_DISCONNECTING; 667 goto out;
The following is an explanation of the logic.
The only code that goto has for the sock_error
label in inet_stream_connect
is a check to see if the socket was closed by RST, timeout, another process, or an error.
In the label sock_error
If we can restore the socket error report, do it, otherwise the error state will be ECONNABORTED
As a comment by Celada , I also recommend opening a new socket every time.