Skip to content

fix(monitor): anchor tmux session checks to avoid matching other instances - #4989

Open
yourfate wants to merge 1 commit into
GameServerManagers:developfrom
yourfate:fix/monitor-session-pattern-anchor
Open

yourfate wants to merge 1 commit into
GameServerManagers:developfrom
yourfate:fix/monitor-session-pattern-anchor

Conversation

@yourfate

@yourfate yourfate commented Oct 5, 2026

Copy link
Copy Markdown

Description

fn_monitor_check_session uses unanchored pgrep -f/pkill -f patterns for the v23.5.0 migration checks. When several instances run under the same user and one session name is a prefix of another (the standard multi-instance naming, e.g. vhserver and vhserver-2), the shorter instance's "old type tmux session" check:

pgrep -fc -u "${USER}" "tmux new-session -d -x 80 -y 23 -s vhserver"

matches the command line of the other instance's monitor running the same check concurrently:

pgrep -fc -u vhserver tmux new-session -d -x 80 -y 23 -s vhserver-2

So whenever both monitors run at the same moment (typical with identical */5 cron entries), the first instance logs PIDS with old type tmux session are running and is restarted. Only the instance with the shorter name is affected, which matches the reports in #4575.

This PR anchors both migration patterns to the start of the command line and requires the session name to be followed by a space or end of line (^tmux ... -s ${sessionname}( |$)). Genuine old-style sessions still match; pgrep processes and other instances no longer do.

Fixes #4575

Type of change

  • Bug fix (a change which fixes an issue).
  • New feature (a change which adds functionality).
  • New Server (new server added).
  • Refactor (restructures existing code).
  • Comment update (typo, spelling, explanation, examples, etc).

Testing

  • Commands/tests run:
    • Observed on a live host with vhserver and vhserver-2 (same user, */5 monitor cron each): 162 of 2303 vhserver monitor runs logged the spurious "old type tmux session" error and restarted the server; vhserver-2 had zero.
    • Matched old vs. new pattern against real command lines with grep -E:
      • pgrep -fc -u vhserver tmux new-session -d -x 80 -y 23 -s vhserver-2 → old: match, new: no match
      • tmux -L vhserver-2-f1b0cb57 new-session -d -x 80 -y 23 -s vhserver-2 ./valheim... → no match (both)
      • tmux new-session -d -x 80 -y 23 -s vhserver ./valheim... (genuine old-type session) → match (both)
    • bash -n lgsm/modules/command_monitor.sh
  • Result: as expected above.
  • Environment used (distro/version): Debian 13 (trixie), LXC on Proxmox, LinuxGSM v26.2.0.

Risk and rollback

  • Risk level: low
  • Rollback plan: revert this commit.

Breaking changes

  • No breaking changes.
  • Breaking changes included (describe below).

Documentation impact

  • No documentation update required.
  • User documentation update required.
  • Developer documentation update required.

Checklist

PR will not be merged until all steps are complete.

  • This pull request links to an issue.
  • This pull request uses the develop branch as its base.
  • This pull request subject follows the Conventional Commits standard.
  • This code follows the style guidelines of this project.
  • I have performed a self-review of my code.
  • I have provided a detailed enough description of this PR.

🤖 Generated with Claude Code

…ances

The monitor's session migration checks used unanchored pgrep/pkill
patterns. With multiple instances under one user where one session name
is a prefix of another (e.g. vhserver and vhserver-2), the shorter
instance's "old type tmux session" check matched the other instance's
concurrently running pgrep command line, causing spurious restarts
whenever both monitors ran at the same time.

Anchor the patterns to the start of the command line and require the
session name to be followed by a space or end of line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant