Skip to content

Stale pid file may cause the launch script to incorrectly report that the service is running if a new process has been allocated the same pid #25651

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

Closed
eduault opened this issue Mar 16, 2021 · 1 comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug

Comments

@eduault
Copy link

eduault commented Mar 16, 2021

Spring Boot version : 2.2.4.RELEASE
OS (uname -a) : Linux hostname 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

On a Linux server, there is an init.d "service_name" service implemented as a Spring Boot "executable".
The "service service_name status" Linux command used in supervision returned sometimes "Running", but the service was inactive.
So I run the following in a bash shell to reproduce this bug :

for i in {1..10000}
do
	service service_name status
	echo $?
done

The output contains an error ::

Running [15344]
0

I think I found the root cause of this bug. The Linux command "service service_name status" (with the name of one Linux init.d service implemented as a Spring Boot "executable") uses a process number (PID) to know if the service is active. It is problematic, because when the service is idle (and the PID of its last run was saved), a new unrelated Linux process might be assigned this PID. And the command will then indicate that this service is active, when it is not.

The problematic code is in this file ::
https://github.com/spring-projects/spring-boot/blob/v2.2.4.RELEASE/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

This file contains ::

isRunning() {
  ps -p "$1" &> /dev/null
}
status() {
  working_dir=$(dirname "$jarfile")
  pushd "$working_dir" > /dev/null
  [[ -f "$pid_file" ]] || { echoRed "Not running"; return 3; }
  pid=$(cat "$pid_file")
  isRunning "$pid" || { echoRed "Not running (process ${pid} not found)"; return 1; }
  echoGreen "Running [$pid]"
  return 0
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 16, 2021
@eduault eduault changed the title Bug : "service service_name status" of an inactive init.d service can return "Running" Bug : "service service_name status" with an inactive init.d service can return "Running" Mar 16, 2021
@snicoll snicoll changed the title Bug : "service service_name status" with an inactive init.d service can return "Running" "service service_name status" with an inactive init.d service can return "Running" Mar 16, 2021
@wilkinsona wilkinsona changed the title "service service_name status" with an inactive init.d service can return "Running" Stale pid file may cause the launch script to incorrectly report that the service is running if a new process has been allocated the same pid Mar 17, 2021
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 17, 2021
@wilkinsona wilkinsona added this to the 2.3.x milestone Mar 17, 2021
@wilkinsona wilkinsona modified the milestones: 2.3.x, 2.4.x Jun 10, 2021
@wilkinsona wilkinsona modified the milestones: 2.4.x, 2.5.x Nov 15, 2021
@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.6.x May 19, 2022
@wilkinsona
Copy link
Member

I don't think there's anything meaningful that we can do about this in our launch script. If it's causing problems, using daemontools instead may produce better results.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2022
@wilkinsona wilkinsona removed this from the 2.6.x milestone Jul 20, 2022
@wilkinsona wilkinsona added the status: declined A suggestion or change that we don't feel we should currently apply label Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants