Skip to content

fix: make start.sh --stop skip nodes in other directories - #7075

Merged
kuny0707 merged 4 commits into
tronprotocol:release_v4.8.3from
Little-Peony:fix/start-sh-stop-own-node
Nov 4, 2026
Merged

kuny0707 merged 4 commits into
tronprotocol:release_v4.8.3from
Little-Peony:fix/start-sh-stop-own-node

Conversation

@SeriousCoding789

@SeriousCoding789 SeriousCoding789 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

start.sh --stop now stops only the node started from the current directory: a matching process counts only when its working directory is the current directory (read from /proc/<pid>/cwd on Linux or with lsof on macOS, compared by device and inode).

  • start.sh
    • processDir / matchDirPid: check the working directory on both the pid-file path and the path without a pid file (a node started by an earlier script). A process running from another directory is left running, with a warning when it is the one in the pid file.
    • Working directory unreadable or deleted: with a pid file, the recorded id is trusted; without one, --stop fails and asks for the id in the pid file if this user can signal the process, otherwise it only warns. Zombies are skipped.
    • stopService returns 2 when the node cannot be stopped (kill fails on a live process, or it survives SIGKILL); --stop exits 2 and a restart starts nothing.
  • shell.md: describe the directory check and its limits.

Why are these changes required?

Since #7003, a directory with start.log but no pid file still finds its node by jar name across the whole machine, so --stop or a restart there also stops same-named nodes in other directories, even when its own node is not running. The pid-file path checks only the jar name, so a reused id can stop another directory's node. And stopService returns success when the node cannot be stopped, so a restart starts a second node and overwrites the pid file.

The node is started from its directory and the JVM keeps that working directory, so the working directory tells the nodes apart.

This PR has been tested by:

  • Manual Testing with dummy processes running -jar <test jar> from separate directories:
    • macOS (bash 3.2, lsof): 302 checks pass, 78 of them on --stop.
    • Linux (Docker eclipse-temurin:17-jdk, sh is dash): 81 --stop checks with default capabilities and 78 with SYS_PTRACE, plus 35 general checks, all pass.
    • Scenarios: same-named nodes in other directories, reused id, another user's node, unreadable or deleted working directory, renamed directory, letter case, symlink and space in the path, sh start.sh, SIGKILL timeout, a node restarted by a supervisor, zombie.
  • Two JDK 17 nodes with the same jar name on macOS: only the node of the current directory is stopped.
  • bash -n start.sh; shellcheck reports nothing new.
Scenario Before After
No pid file; same-named nodes in A and B; --stop in A both stopped A stopped
No pid file in A; only B running; --stop in A B stopped B running
Pid file in A holds a reused id of B's node B stopped B running, warning
No pid file; working directory unreadable or deleted stopped by jar name error, exit 1; stopped once the id is in the pid file
Node cannot be stopped (no permission, or restarted by a supervisor) --stop exits 0, restart starts another node --stop exits 2, restart starts nothing

Follow up

None.

Extra details

  • pgrep and pkill cannot filter by working directory, hence /proc and lsof; a lock file or systemd units would change how nodes are deployed.
  • Directories are compared by device and inode because bash 3.2's pwd -P keeps the letter case typed in cd on case-insensitive APFS, and lsof keeps the last path of a deleted directory.
  • A recorded process running from another directory is left running, because a moved node directory and a reused id look the same; the warning names that directory.
  • Reading another user's working directory needs root, so for a normal user another user's node only gets a warning.

A directory with a start.log but no pid file was used by an earlier
version of the script, and --stop found its node by the jar name alone,
so it also stopped nodes with the same jar name in other directories.
Pick the node whose working directory is the current directory, read
from /proc on Linux or with lsof on macOS. When neither is available,
exit with an error that asks for the process id in the pid file.
Comment thread start.sh Resolved
Comment thread start.sh Resolved
The pid file path matched only the jar name, so a recorded id reused by a
node that runs the same jar from another directory would have stopped
that node. A recorded process whose working directory reads as another
directory is now taken as a stopped node and the pid file is emptied;
one whose directory cannot be read keeps the pid file and is stopped as
before.

Without a pid file, a process whose working directory could not be read
was skipped silently, so --stop could report the node stopped while it
was still running. If this user can signal such a process, --stop and
restart now end with an error on stderr; a process this user cannot
signal is left running with a warning.
Comment thread start.sh Resolved
Comment thread shell.md Resolved
stopService ended with sleep 5 and returned success even when the node
was still running: a process this user cannot signal made every kill
fail until the timeout, and a restart then started another node and
wrote its id over the pid file of the running one. A failed signal now
counts while the process still exists, and a node still running after
SIGKILL fails too; both report an error on stderr and return 2, which
ends --stop with that status and stops a restart before it starts a
node. A return of 1 still means no node was ever started from the
directory, so --run starts the node as before.

shell.md now states that the directory check needs a readable working
directory, and that a pid file whose process cannot be inspected is
trusted as recorded.
Comment thread start.sh Resolved
Comment thread start.sh Resolved
Comment thread start.sh Resolved
Comment thread shell.md Resolved
Comment thread start.sh Resolved
Compare a process's working directory with the current directory by
device and inode instead of by path, so a directory entered with a
different letter case or through a symlink still matches. A deleted
working directory now counts as unreadable: on Linux its path ends in
" (deleted)", and lsof keeps its last path, which counts only while it
still leads to the inode lsof reports.

Without a pid file, a process that can be signalled but whose directory
cannot be read is skipped once it no longer runs the jar, so a zombie
after SIGKILL is not reported as unreadable. The pid-file warning names
the directory the recorded process runs from instead of saying the node
has stopped.

Shorten the shell.md description of --stop, and note that only a
process this user can signal makes it fail.
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.3 milestone Nov 3, 2026
@kuny0707
kuny0707 merged commit 80f6d51 into tronprotocol:release_v4.8.3 Nov 4, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this to Done in java-tron Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants