sock/posix: Add MSG_NOSIGNAL to prevent SIGPIPE for a socket that may be closed

We try avoiding write a closed socket by checking if the return value
of recv() is zero. However it is not possible to completely avoid writing
a socket which is already closed by the target.

Repeatedly adding/removing listener in the NVMe-oF TCP target caused
SIGPIPE to the NVMe-oF initiator.

Fix the issue by adding MSG_NOSIGINAL to the flag of sendmsg().

Signed-off-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12119 (master)

(cherry picked from commit 5fd1f68b63)
Change-Id: I273679c91c4b867792e966b1dc2121f6d2188f16
Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12480
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Shuhei Matsumoto 2022-04-01 07:06:16 +09:00 committed by Keith Lucas
parent 2c2fea9ea4
commit 07ae9b780e

View File

@ -730,11 +730,11 @@ _sock_flush(struct spdk_sock *sock)
msg.msg_iovlen = iovcnt;
#ifdef SPDK_ZEROCOPY
if (psock->zcopy) {
flags = MSG_ZEROCOPY;
flags = MSG_ZEROCOPY | MSG_NOSIGNAL;
} else
#endif
{
flags = 0;
flags = MSG_NOSIGNAL;
}
rc = sendmsg(psock->fd, &msg, flags);
if (rc <= 0) {