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>
Change-Id: I273679c91c4b867792e966b1dc2121f6d2188f16
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12119
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2022-04-01 07:06:16 +09:00 committed by Tomasz Zawadzki
parent 75209b1d53
commit 5fd1f68b63

View File

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