Cannot restart nginx when listening on UNIX domain sockets
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
nginx (Ubuntu) |
Fix Released
|
Low
|
Unassigned | ||
Jammy |
Fix Released
|
Low
|
Michał Małoszewski |
Bug Description
[Impact]
* Restarting nginx fails on Jammy is listening on unix sockets is configured. It produces the errors in the error.log.
* That issue is caused by the behavior of the custom socket closing code in
ngx_master_
* The fix is to replace the custom socket closing code in
ngx_master_
[Test Plan]
Make a container for testing:
$ lxc launch ubuntu-daily:jammy jammy-test
$ lxc shell jammy-test
Type in:
# apt install -y nginx
# systemctl stop nginx
Then type in:
# cat << EOF > /etc/nginx/
server {
listen unix:/run/
root /var/www/files;
location / {
try_files \$uri =404;
}
}
EOF
# service nginx start
# service nginx stop
# service nginx restart
Enter the /var/log/
Example of failed output:
You will be able to see the error logs in the error.log file.
2023/06/01 10:39:02 [emerg] 895#895: bind() to unix:/run/
2023/06/01 10:39:02 [emerg] 895#895: bind() to unix:/run/
2023/06/01 10:39:02 [emerg] 895#895: bind() to unix:/run/
2023/06/01 10:39:02 [emerg] 895#895: bind() to unix:/run/
2023/06/01 10:39:02 [emerg] 895#895: bind() to unix:/run/
2023/06/01 10:39:02 [emerg] 895#895: still could not bind()
Moreover: systemctl status nginx
× nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/
Drop-In: /run/systemd/
Active: failed (Result: exit-code) since Thu 2023-06-01 10:39:05 UTC; 56s ago
Docs: man:nginx(8)
Process: 894 ExecStartPre=
Process: 895 ExecStart=
Jun 01 10:39:02 jammy-test systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 01 10:39:02 jammy-test nginx[895]: nginx: [emerg] bind() to unix:/run/
Jun 01 10:39:03 jammy-test nginx[895]: nginx: [emerg] bind() to unix:/run/
Jun 01 10:39:03 jammy-test nginx[895]: nginx: [emerg] bind() to unix:/run/
Jun 01 10:39:04 jammy-test nginx[895]: nginx: [emerg] bind() to unix:/run/
Jun 01 10:39:04 jammy-test nginx[895]: nginx: [emerg] bind() to unix:/run/
Jun 01 10:39:05 jammy-test nginx[895]: nginx: [emerg] still could not bind()
Jun 01 10:39:05 jammy-test systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jun 01 10:39:05 jammy-test systemd[1]: nginx.service: Failed with result 'exit-code'.
Jun 01 10:39:05 jammy-test systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Example of successful output:
No errors in the error.log file.
Nginx can be restarted without any problems.
[Where problems could occur]
* After installing nginx, causing the issue and then installing nginx with
fix or simply re-installing the same version - the nginx fails to upgrade,
because the former issue that is caused makes the service non-startable and
the upgrade will trigger a service restart in postinst. Since that fails it
cannot upgrade.
If you are affected, just remove the offending socket and restart the
service - after that (due to the fix) you will not be affected by this
again.
-------
As discussed in [1], there is a bug in nginx [2] which makes Ubuntu's systemd unit restarts fail when nginx is litening on a unix domain socket. This happens because nginx fails to remove the socket during its shutdown process.
This issue has been reported in Debian in [3], and has been fixed upstream since 1.19.1, with the following patch: [4].
To reproduce the issue, run the following commands from a jammy machine:
# apt install -y nginx
# systemctl stop nginx
# mkdir -p /var/www/files
# echo hello > /var/www/
# cat << EOF > /run/serve-
server {
listen unix:/run/
root /var/www/files;
location / {
try_files $uri =404;
}
}
EOF
# systemctl start nginx
Verify it works with:
# echo -e "GET /hello HTTP/1.0\r\n" | netcat -U /run/serve-
And restart the service:
# systemctl restart nginx
This will throw an error and the service will end in a failed state.
Verify that the socket file in /run/serve-
Removing the socket file should allow you to restart the service.
[1] https:/
[2] https:/
[3] https:/
[4] http://
Related branches
- git-ubuntu bot: Approve
- Athos Ribeiro (community): Approve
- Canonical Server Reporter: Pending requested
-
Diff: 84 lines (+62/-0)3 files modifieddebian/changelog (+9/-0)
debian/patches/lp1957320-jammy-fixed-sigquit-issue-with-unix-sockets.patch (+52/-0)
debian/patches/series (+1/-0)
Changed in nginx (Ubuntu Jammy): | |
status: | New → Triaged |
tags: | added: bitesize |
Changed in nginx (Ubuntu Jammy): | |
status: | Triaged → In Progress |
description: | updated |
tags: | added: server-todo |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
tags: | removed: bitesize |
description: | updated |
description: | updated |
description: | updated |
description: | updated |
Adding this to the Ubuntu Server backlog to match LP: #1919965