netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: Network Development <netdev@vger.kernel.org>
Subject: How do I avoid recvmsg races with IP_RECVERR?
Date: Tue, 2 Jun 2015 12:40:33 -0700	[thread overview]
Message-ID: <CALCETrW-jkMrEjidwCTraeAaHCHA_+9eExQAz2phvn=OB8RMhQ@mail.gmail.com> (raw)

As far as I can tell, enabling IP_RECVERR causes the presence of a
queued error to cause recvmsg, etc to return an error (once).  It's
worse, though: a new error can be queued asynchronously at any time,
this setting sk_err to a nonzero value.  How do I sensibly distinguish
recvmsg failures to to genuine errors receiving messages from recvmsg
failures because there's a queued error?

The only way I can see to get reliable error handling is to literally
call recvmsg in a loop:

while (true /* or while POLLIN is set */) {
  int ret = recvmsg(..., MSG_ERRQUEUE not set);
  if (ret < 0 && /* what goes here? */) {
    whoops!  this might be a harmless asynchronous error!
    take no action!
  }

  /* if POLLERR (or maybe unconditionally), recvmsg(..., MSG_ERRQUEUE);
}

The problem is that, if I'm screwing something up (thus causing EINVAL
or something similar), this will just spin forever.

Am I missing something here?  Would it make sense to add
MSG_IGNORE_ERROR to suppress the sock_error check or IP_RECVERR=2 to
stop setting sk_err?


Thanks,
Andy

             reply	other threads:[~2015-06-02 19:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-02 19:40 Andy Lutomirski [this message]
2015-06-02 21:17 ` How do I avoid recvmsg races with IP_RECVERR? Hannes Frederic Sowa
2015-06-02 21:33   ` Andy Lutomirski
2015-06-02 21:42     ` Hannes Frederic Sowa
2015-06-02 21:49       ` Andy Lutomirski
2015-06-02 21:50       ` Hannes Frederic Sowa
2015-06-03  0:03         ` Andy Lutomirski
2015-06-03  0:33           ` Hannes Frederic Sowa
2015-06-03  0:56             ` Andy Lutomirski
2016-04-09  0:02             ` Andy Lutomirski

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='CALCETrW-jkMrEjidwCTraeAaHCHA_+9eExQAz2phvn=OB8RMhQ@mail.gmail.com' \
    --to=luto@kernel.org \
    --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 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).