glyustb / mogilefs

Automatically exported from code.google.com/p/mogilefs
0 stars 0 forks source link

mogstored: can't start under FreeBSD with daemonize option specified #72

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Under FreeBSD I was not able to start mogstored if the daemonize option was 
specified: it terminated unexpectedly.

It turned up that the issue was related to kqueue initialization in 
Danga::Socket.

Danga::Socket does poller initialization only once (see _InitPoller), on the 
first usage.

In mogstored we have the following sequence:

{{{
 $httpsrv->start       # Danga::Socket (and kqueue) is initialized here
 Perlbal::daemonize()  # fork(2)
 ...
 Mogstored::SideChannelListener # kqueue is used again by Danga::Socket
}}}

The issue is that the kernel event queue is not inherited by a child created 
with fork(2). See e.g. kqueue(2) manual page:

http://www.freebsd.org/cgi/man.cgi?query=kqueue&apropos=0&sektion=0&manpath=Free
BSD+9.0-RELEASE&arch=default&format=html

So when in SideChannelListener kevent is called by Danga::Socket using the 
inhereted kqueue descriptor, "bad file descriptor" error is generated (which 
can be checked with ktrace).

The attached patch, which moves $httpsrv->start after daemonize(), fixes the 
issue for me.

Original issue reported on code.google.com by to.my.trociny@gmail.com on 16 Sep 2012 at 7:24

Attachments:

GoogleCodeExporter commented 9 years ago
Hi!

Eric cc'ed you from the list, but this should be fixed for 2.67 (is currently 
in our next tree). Closing this out.

Original comment by dorma...@rydia.net on 18 Jan 2013 at 9:27