Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pid file not properly overwritten #3425

Closed
khera opened this Issue Aug 1, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@khera
Copy link

khera commented Aug 1, 2013

I had an instance running on a server, and the PID file had a 5-digit process ID in it. I did a restart, and the new process ID was 4-digits, but the file sitll had the 5th digit from the prior process.

When writing the pid file, it should truncate it first if it already exists.

Running elasticsearch 0.90.0 on FreeBSD.

Thanks!

@ghost ghost assigned spinscale Aug 2, 2013

@spinscale

This comment has been minimized.

Copy link
Member

spinscale commented Aug 2, 2013

Hey,

can you please provide more information. how you did this? I just tried the following (under Mac OS):

bin/elasticsearch -p /tmp/pid
sleep 10 && cat /tmp/pid
36756
bin/elasticsearch -p /tmp/pid
sleep 10 && cat /tmp/pid
36792

In my case the truncation works flawlessly (there is no check in elasticsearch if the pid file already exists). Anything you did different with the exception of your operating system? I am wondering if the sigar library is completely supported under freebsd, but judging from the official documentation it looks like it.

@khera

This comment has been minimized.

Copy link
Author

khera commented Aug 2, 2013

Your example shows the PID both of length 5.

Try this:

echo aaaaaaaaaa > /tmp/pid

then run your test.

Here is what it looks like to me:

[root@logger]# /usr/local/etc/rc.d/elasticsearch start
Starting elasticsearch.
[root@logger]# cat /var/run/elasticsearch.pid
40757[root@logger]#
[root@logger]# /usr/local/etc/rc.d/elasticsearch stop
Stopping elasticsearch.
[root@logger]# echo aaaaaaaaaa > /var/run/elasticsearch.pid
[root@logger]# cat /var/run/elasticsearch.pid
aaaaaaaaaa
[root@logger]# /usr/local/etc/rc.d/elasticsearch start
Starting elasticsearch.
[root@logger]# cat /var/run/elasticsearch.pid
75686aaaaa

Basically, if the pid assigned to elastic search is 5 digits long, and then
after a restart, the PID becomes 3 or 4 digits long, whatever was leftover
will still be there.

So if the first PID is 12345 and the second pid is 4321, what will be in
the file is 43215.

On FreeBSD, the PIDs are not necessarily monotonically increasing, so this
has actually happened to me, and is not just a theoretical problem. I'm not
so familiar with Java, but in C or Perl, I'd add the O_TRUNC flag to the
file open.

Thanks!

On Fri, Aug 2, 2013 at 3:05 AM, Alexander Reelsen
notifications@github.comwrote:

Hey,

can you please provide more information. how you did this? I just tried
the following (under Mac OS):

bin/elasticsearch -p /tmp/pid
sleep 10 && cat /tmp/pid
36756
bin/elasticsearch -p /tmp/pid
sleep 10 && cat /tmp/pid
36792

In my case the truncation works flawlessly (there is no check in
elasticsearch if the pid file already exists). Anything you did different
with the exception of your operating system? I am wondering if the sigar
library is completely supported under freebsd, but judging from the
official documentation it looks like it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3425#issuecomment-21989725
.

@spinscale

This comment has been minimized.

Copy link
Member

spinscale commented Aug 3, 2013

sorry, I got you wrong. Will fix it.

Thanks for your patience to report!

@spinscale spinscale closed this in 9c7a87f Aug 5, 2013

spinscale added a commit that referenced this issue Aug 5, 2013

Overwriting pidfile on startup
The current implementation does not overwrite, but only prepend the new PID into the pidfile.
So if the process is 4 digits long, but the file is already there with a 5 digit number, the file will contain 5 digits after the write.

Note: If the pidfile still exists this usually means, there either is already an instance running using this pidfile or the process has not finished correctly.

Closes #3425

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Overwriting pidfile on startup
The current implementation does not overwrite, but only prepend the new PID into the pidfile.
So if the process is 4 digits long, but the file is already there with a 5 digit number, the file will contain 5 digits after the write.

Note: If the pidfile still exists this usually means, there either is already an instance running using this pidfile or the process has not finished correctly.

Closes elastic#3425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.