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

Closed as not planned
@eduault

Description

@eduault

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently applytype: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions