From: David Miller <davem@davemloft.net>
To: jbaron@akamai.com
Cc: netdev@vger.kernel.org, rientjes@google.com,
rweikusat@mobileactivedefense.com, edumazet@google.com
Subject: Re: [PATCH v2 net-next] af_unix: ensure POLLOUT on remote close() for connected dgram socket
Date: Fri, 03 Aug 2018 16:44:44 -0700 (PDT) [thread overview]
Message-ID: <20180803.164444.8668116949268659.davem@davemloft.net> (raw)
In-Reply-To: <1533331493-26286-1-git-send-email-jbaron@akamai.com>
From: Jason Baron <jbaron@akamai.com>
Date: Fri, 3 Aug 2018 17:24:53 -0400
> Applications use -ECONNREFUSED as returned from write() in order to
> determine that a socket should be closed. However, when using connected
> dgram unix sockets in a poll/write loop, a final POLLOUT event can be
> missed when the remote end closes. Thus, the poll is stuck forever:
>
> thread 1 (client) thread 2 (server)
>
> connect() to server
> write() returns -EAGAIN
> unix_dgram_poll()
> -> unix_recvq_full() is true
> close()
> ->unix_release_sock()
> ->wake_up_interruptible_all()
> unix_dgram_poll() (due to the
> wake_up_interruptible_all)
> -> unix_recvq_full() still is true
> ->free all skbs
>
>
> Now thread 1 is stuck and will not receive anymore wakeups. In this
> case, when thread 1 gets the -EAGAIN, it has not queued any skbs
> otherwise the 'free all skbs' step would in fact cause a wakeup and
> a POLLOUT return. So the race here is probably fairly rare because
> it means there are no skbs that thread 1 queued and that thread 1
> schedules before the 'free all skbs' step.
>
> This issue was reported as a hang when /dev/log is closed.
>
> The fix is to signal POLLOUT if the socket is marked as SOCK_DEAD, which
> means a subsequent write() will get -ECONNREFUSED.
>
> Reported-by: Ian Lance Taylor <iant@golang.org>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Rainer Weikusat <rweikusat@mobileactivedefense.com>
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Jason Baron <jbaron@akamai.com>
> ---
> v2: use check for SOCK_DEAD, since skb's can be purged in unix_sock_destructor()
Applied, thanks Jason.
prev parent reply other threads:[~2018-08-04 1:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-03 21:24 [PATCH v2 net-next] af_unix: ensure POLLOUT on remote close() for connected dgram socket Jason Baron
2018-08-03 23:44 ` David Miller [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180803.164444.8668116949268659.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jbaron@akamai.com \
--cc=netdev@vger.kernel.org \
--cc=rientjes@google.com \
--cc=rweikusat@mobileactivedefense.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).