﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
2467	In daemon mode nginx completes detaching before the service is ready	cryptonector@…		"This affects all versions, and is a very common problem in daemons of all kinds.

This makes tests that start nginx racy, and the workaround is to loop over polling a health end-point, sleeping between polling.  The workaround makes tests slower.  Similar considerations can affect actual production services.

The bug is here: https://github.com/nginx/nginx/blob/a64190933e06758d50eea926e6a55974645096fd/src/os/unix/ngx_daemon.c#L26 where ngx_daemon() calls exit(0) immediately on the parent-side of fork().  Instead the parent should block waiting for the child to indicate that it has opened all the sockets it will listen on and called listen() on all of them.

Examples of how to implement this (prefix https to all of these -- I can't as otherwise my ticket gets rejected as spam!):

 - //github.com/heimdal/heimdal/blob/master/lib/roken/detach.c
 - //github.com/stefanberger/swtpm/blob/master/src/swtpm/daemonize.c
 - //src.illumos.org/source/search?full=&defs=daemonize*&refs=&path=&hist=&type=&xrd=&nn=1&si=defs&searchall=true&si=defs
 - //github.com/openvswitch/ovs/blob/master/lib/daemon-unix.c#L441
 - //fossies.org/linux/darkstat/conv.c#L225
 - //github.com/emikulic/darkhttpd/blob/master/darkhttpd.c#L2688

There are many many more to be found."	enhancement	closed	minor		nginx-core		wontfix			all platforms and operating systems	all versions
