Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 716700 - www-servers/nginx-1.16.1-r1: systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Summary: www-servers/nginx-1.16.1-r1: systemd[1]: nginx.service: Failed to parse PID f...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal minor (vote)
Assignee: Thomas Deutschmann (RETIRED)
URL: https://trac.nginx.org/nginx/ticket/1897
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-08 15:24 UTC by Erik Quaeghebeur
Modified: 2020-04-11 21:11 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Quaeghebeur 2020-04-08 15:24:21 UTC
There is a known (harmless?) race condition when systemd starts nginx on 1-CPU systems. Suggested fixes can be found:

https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864
https://www.cloudinsidr.com/content/heres-fix-nginx-error-failed-read-pid-file-linux/

Reproducible: Always
Comment 1 Thomas Deutschmann (RETIRED) gentoo-dev 2020-04-08 20:25:32 UTC
The linked bug report contains a comment that

> ExecStopPost=/bin/rm -f /run/nginx.pid
would also help. I.e. the problem seems to be a previous pidfile?!

Because we do

> stop_post() {
>         rm -f ${pidfile}
> }
already in runscript, the ExecStopPost would be an acceptable solution for me.

Can you confirm that this will solve the problem?
Comment 2 Erik Quaeghebeur 2020-04-09 10:46:06 UTC
(In reply to Thomas Deutschmann from comment #1)
> The linked bug report contains a comment that
> 
> > ExecStopPost=/bin/rm -f /run/nginx.pid
> would also help. I.e. the problem seems to be a previous pidfile?!

No, the problem is not a previous pidfile. It is removed correctly. As I said and is described in the linked ubuntu bug, the issue is a race condition.

Furthermore, the linked ubuntu bug, comment 7 <https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864/comments/7> says:

> If this is too much of a change, another workaround is removing the PIDFile option, and adding the line:
> ExecStopPost=/bin/rm -f /run/nginx.pid

In the service file, there is, currently, 

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -QUIT $MAINPID

So I guess that what is meant, is to change this to

[Service]
Type=forking
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -QUIT $MAINPID
ExecStopPost=/bin/rm -f /run/nginx.pid

But I have no idea how this impacts things. (I am neither an expert in systemd nor in nginx.)

> Because we do
> 
> > stop_post() {
> >         rm -f ${pidfile}
> > }
> already in runscript, the ExecStopPost would be an acceptable solution for
> me.
> 
> Can you confirm that this will solve the problem?

Not at this point. And if it would for me, it could create new problems for others.

What is the reason for not using the patch <https://launchpadlibrarian.net/426320897/nginx-fix-pidfile.8.patch>? (I've informed whether it is supposed to go upstream.)
Comment 3 Thomas Deutschmann (RETIRED) gentoo-dev 2020-04-09 14:30:48 UTC
At the moment I can't tell if the patch is solving the problem the correct way. And I don't feel comfortable in general adding a patch without any comment from upstream regarding the issue itself.
Comment 4 Erik Quaeghebeur 2020-04-10 09:08:01 UTC
(In reply to Thomas Deutschmann from comment #3)
> At the moment I can't tell if the patch is solving the problem the correct
> way. And I don't feel comfortable in general adding a patch without any
> comment from upstream regarding the issue itself.
I understand. I have submitted an upstream ticket: https://trac.nginx.org/nginx/ticket/1952#ticket. Let's wait to see what they say.
Comment 5 Erik Quaeghebeur 2020-04-11 13:19:49 UTC
(In reply to Erik Quaeghebeur from comment #4)
> I have submitted an upstream ticket:
> https://trac.nginx.org/nginx/ticket/1952#ticket. Let's wait to see what they
> say.

They decide it's a WONTFIX and that the Ubuntu patch is not the good approach:

https://trac.nginx.org/nginx/ticket/1897

Closing as RESOLVED WONTFIX.
Comment 6 Thomas Deutschmann (RETIRED) gentoo-dev 2020-04-11 13:25:23 UTC
Is it really just a message or is it causing some problems like systemctl will report degraded state?

I think we can add

> ExecStartPost=/bin/sleep 0.1

as workaround to systemd service file until a systemd version with

> Type=pid-file
landed in Gentoo.
Comment 7 Erik Quaeghebeur 2020-04-11 13:57:29 UTC
(In reply to Thomas Deutschmann from comment #6)
> Is it really just a message or is it causing some problems like systemctl
> will report degraded state?
No problems apparent. Does not cause a degraded state report.

> I think we can add
> 
> > ExecStartPost=/bin/sleep 0.1
> 
> as workaround to systemd service file until a systemd version with
> 
> > Type=pid-file
> landed in Gentoo.
That you can do. I tested it, and it seems to remove the issue for me.
Comment 8 Larry the Git Cow gentoo-dev 2020-04-11 21:11:30 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ebd358e0aaa62b455d1eb318f509bb1804fe3285

commit ebd358e0aaa62b455d1eb318f509bb1804fe3285
Author:     Thomas Deutschmann <whissi@gentoo.org>
AuthorDate: 2020-04-11 20:45:27 +0000
Commit:     Thomas Deutschmann <whissi@gentoo.org>
CommitDate: 2020-04-11 21:10:37 +0000

    www-servers/nginx: add workaround for race-condition on systemd
    
    Closes: https://bugs.gentoo.org/716700
    Package-Manager: Portage-2.3.98, Repoman-2.3.22
    Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>

 www-servers/nginx/files/nginx.service-r1 | 1 +
 1 file changed, 1 insertion(+)