From 07ae9b780eff8d3bd9e9818bee601cd6eec3eb8b Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 1 Apr 2022 07:06:16 +0900 Subject: [PATCH] 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 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12119 (master) (cherry picked from commit 5fd1f68b63a668c4b3aef365114c668a3205e825) Change-Id: I273679c91c4b867792e966b1dc2121f6d2188f16 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12480 Reviewed-by: Tomasz Zawadzki Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- module/sock/posix/posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index ab9efd712..11b48ed2d 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -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) {