linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mateusz Guzik <mguzik@redhat.com>
To: Shawn Landden <shawnlandden@gmail.com>
Cc: Jason Baron <jbaron@akamai.com>,
	linux-fsdevel@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Tom Herbert <therbert@google.com>
Subject: Re: disappearing listen()ed SO_REUSEPORT sockets across fork() when using epoll
Date: Mon, 25 Nov 2013 21:05:53 +0100	[thread overview]
Message-ID: <20131125200552.GA5826@mguzik.redhat.com> (raw)
In-Reply-To: <CAJusiZWCrDovv_w29LeFA6m61CdWs4Ljxhwf_chNpNVGvmUKLA@mail.gmail.com>

On Mon, Nov 25, 2013 at 11:53:24AM -0800, Shawn Landden wrote:
> On Mon, Nov 25, 2013 at 10:05 AM, Jason Baron <jbaron@akamai.com> wrote:
> > On 11/22/2013 12:53 PM, Shawn Landden wrote:
> >> Hello, when running the attached program on 3.12 child processes
> >> are missing a socket fd opened, set with SO_REUSEPORT, listen()ed to,
> >> and added to epoll_ctl().
> >>
> >> This is the output I get when pointing "wget http://localhost:5555/"
> >> at the attached program:
> >>
> >> main PID 31591
> >> PID 31634 started
> >> PID 31634 accept()ed connection
> >> PID 31635 started
> >> PID 31636 started
> >> PID 31635 accept() failed: Bad file descriptor
> >> PID 31636 accept() failed: Bad file descriptor
> >> PID 31634 accept()ed connection
> >> PID 31634 accept()ed connection
> >> PID 31634 accept()ed connection
> >> PID 31634 accept()ed connection
> >>
> >>
> >> While I would expect something like:
> >>
> >> main PID 31591
> >> PID 31634 started
> >> PID 31634 accept()ed connection
> >> PID 31635 started
> >> PID 31636 started
> >> PID 31635 accept()ed connection
> >> PID 31636 accept()ed connection
> >>
> >> -more new processes, but inversely proportional to number of listening processes
> >> -accept() always returns successfully
> >>
> >>
> >
> > The 'close(sockfd);' looks to be racing with the accept() calls. Removing seems
> > to get the result you are looking for.
> Interesting. That works, but it shouldn't. The close() is operating in
> the parent, so it shouldn't affect the child,
> there is a leak here of process separation.
> 

You fork, then close sockfd in the parent. Thus, the very first child
can accept connectins just fine.

Subsequent forks give you children without sockfd, thus accept fails.
The first child continues to work just fine.

-- 
Thou shalt not follow the NULL pointer, for chaos and madness await thee
at its end. 

  reply	other threads:[~2013-11-25 20:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-22 17:53 disappearing listen()ed SO_REUSEPORT sockets across fork() when using epoll Shawn Landden
2013-11-25 18:05 ` Jason Baron
2013-11-25 19:53   ` Shawn Landden
2013-11-25 20:05     ` Mateusz Guzik [this message]
2013-11-25 21:03       ` Shawn Landden

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=20131125200552.GA5826@mguzik.redhat.com \
    --to=mguzik@redhat.com \
    --cc=jbaron@akamai.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shawnlandden@gmail.com \
    --cc=therbert@google.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).