Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Once the USR2 signal is received the master process forks, the child process inherits the parents file descriptors including listen(). One process stops accepting connections creating a queue in the kernel. The new process takes over and starts accepting connections.

You can follow the trail by searching for ngx_exec_new_binary in the nginx repo.



Just to add - Nginx normally spawns several worker processes that all process connections to the same port.


Correct but to clarify, only the master process binds to the ports. The master process creates socketpairs to the workers for interprocess communication. The workers accept connections over the shared socket.

https://www.nginx.com/blog/socket-sharding-nginx-release-1-9...

Page also has an example of how SO_REUSEPORT effects flow.


Oh, thanks! I didn't know that. I supposed it worked by inheriting the listening socket but I didn't check.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: