In daemon mode nginx completes detaching before the service is ready
|Reported by:||Owned by:|
|uname -a:||all platforms and operating systems|
|nginx -V:||all versions|
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!):
There are many many more to be found.