All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: David Miller <davem@davemloft.net>, netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH] net: unix: non blocking recvmsg() should not return -EINTR
Date: Wed, 26 Mar 2014 14:25:13 +0000	[thread overview]
Message-ID: <87a9cd82ba.fsf@sable.mobileactivedefense.com> (raw)
In-Reply-To: <1395842972.12610.203.camel@edumazet-glaptop2.roam.corp.google.com> (Eric Dumazet's message of "Wed, 26 Mar 2014 07:09:32 -0700")

Eric Dumazet <eric.dumazet@gmail.com> writes:
> On Wed, 2014-03-26 at 13:17 +0000, Rainer Weikusat wrote:
>> Eric Dumazet <eric.dumazet@gmail.com> writes:
>> > From: Eric Dumazet <edumazet@google.com>
>> >
>> > Some applications didn't expect recvmsg() on a non blocking socket
>> > could return -EINTR. This possibility was added as a side effect
>> > of commit b3ca9b02b00704 ("net: fix multithreaded signal handling in
>> > unix recv routines").
>> >
>> > To hit this bug, you need to be a bit unlucky, as the u->readlock
>> > mutex is usually held for very small periods.
>> 
>> This would mean that 'some applications' are broken, cf
>> 
>> [EAGAIN] or [EWOULDBLOCK]
>>     The socket's file descriptor is marked O_NONBLOCK and no data is
>>     waiting to be received; or MSG_OOB is set and no out-of-band data is
>>     available and either the socket's file descriptor is marked
>>     O_NONBLOCK or the socket does not support blocking to await
>>     out-of-band data.
>> 
>> [EINTR]
>>     This function was interrupted by a signal before any data was
>>     available.
>>     
>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html
>> 
>> and
>> 
>>  EAGAIN or EWOULDBLOCK
>>               The socket is marked nonblocking and the receive operation
>>               would block, or a receive timeout had been set and the
>>               timeout expired before data was received.
>> 
>>  EINTR  The receive was interrupted by delivery of a signal before any
>>         data were available; see signal(7).
>> 
>> [3.27 Linux recvmsg(2)]
>> 
>> since the function was interrupted before any data was available and it
>> is unknown if the condition supposed to be signalled by EAGAIN had
>> otherwise occurred.
>> 
>> A correct 'fix'/ workaround would seem to be using mutex_trylock and
>> abort execution immediately with -EAGAIN in case the operation had to
>> wait for the lock, although this is inconsistent with the usual
>> semantics of 'blocking' which implies that the operation may take an
>> indefinite amount of time because it waits for an external event which
>> might never occur.
>
> Before your patch, -EAGAIN was delivered, -EINTR was _never_ delivered.
>
> Thats a fact.

Indeed. Before this change, a signal could silently get lost for reasons
I outlined in the original mail. This is now no longer the case.

> If you read the manpage, its in this order :
>
> When using a nonblocking socket, and no data is available, EAGAIN or
> EWOULDBLOCK is delivered.
>
> -EINTR is not expected from a non blocking system call. Period.

That's your interpretation of a text which doesn't say so unambigiously
(actually, it pretty much says the exact opposite) and I think this
interpretation is not correct for the reasons I gave (in particular,
that it is unknown if data is available and that EAGAIN implies that it
is known that data is not available).

This is a somewhat interesting problem from a theoretical standpoint,
because there is really no totally satisfactory solution, however, I'm
presently 'over-the-top' buried below a heap of seriously grotty and
misbehaving Java code. Consequently, I suggest to end this discussion
here.

  reply	other threads:[~2014-03-26 14:25 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-26  1:42 [PATCH] net: unix: non blocking recvmsg() should not return -EINTR Eric Dumazet
2014-03-26 13:17 ` Rainer Weikusat
2014-03-26 13:57   ` Rainer Weikusat
2014-03-26 14:09   ` Eric Dumazet
2014-03-26 14:25     ` Rainer Weikusat [this message]
2014-03-26 15:00 ` David Laight
2014-03-26 15:13   ` Rainer Weikusat
2014-03-26 15:25     ` Eric Dumazet
2014-03-26 15:33       ` Eric Dumazet
2014-03-26 19:46       ` Rainer Weikusat
2014-03-26 21:04         ` Rainer Weikusat
2014-03-27  9:36           ` David Laight
2014-03-27 12:40             ` Rainer Weikusat
2014-03-27 12:49               ` Jamal Hadi Salim
2014-03-27 13:02                 ` Rainer Weikusat
2014-03-27 12:53               ` David Laight
2014-03-27 13:29                 ` Rainer Weikusat
2014-03-26 21:05         ` David Miller
2014-03-26 21:21           ` Rainer Weikusat
2014-03-26 21:44             ` Eric Dumazet
2014-03-26 22:06               ` Rainer Weikusat
2014-03-26 22:35                 ` Eric Dumazet
2014-03-26 22:51                   ` Rainer Weikusat
2014-03-26 22:58                     ` Eric Dumazet
2014-03-28 20:35             ` Rainer Weikusat

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=87a9cd82ba.fsf@sable.mobileactivedefense.com \
    --to=rweikusat@mobileactivedefense.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.