Skip to content

Linux idle check: any /dev/pts entry or still-open login blocks idle-stop forever, defeating countActiveSessions' 'idle SSH sessions don't block' design #953

Closed

Description

@scttfrdmn

Found while auditing idle signals for #937. Verified by reading the code only; not observed on an instance.

isIdle checks sessions first, and does it carefully. countActiveSessions -> sysCountActiveSessions counts only sessions with input in the last 5 minutes (from the w idle column). Its doc gives the intent: "so idle SSH/RDP connections don't block idle detection."

Three checks later, on Linux, two presence-only checks undo that:

  • hasActiveTerminals -> sysHasActiveTerminals: any numeric entry in /dev/pts means "Not idle: Active terminals present". A PTY exists for every open SSH session, however long it has been idle, and also for every detached tmux/screen session, every docker run -t / docker exec -t, and every SSM Session Manager shell. None of them needs a human present.
  • hasRecentUserActivity -> sysHasRecentUserActivity: last -s -5min -w. util-linux documents --since as showing "the state of logins since the specified time", which includes sessions that are still logged in, whenever they started. So an open login seems to count as "recent activity" indefinitely. I have not checked this on AL2023.

(hasLoggedInUsers just calls countActiveSessions again, so it is redundant but harmless.)

Effect: on Linux, leaving an SSH session open, or leaving a detached tmux session behind (a common way to run a long job), blocks --idle-timeout forever. This is the "idle-stop can never fire" class of #919/#937, reached through presence checks rather than counters. The 5-minute idle-time logic in countActiveSessions has no effect while a PTY exists.

Windows is consistent: both checks are countActiveSessions() > 0.

Suggested fix: decide which is intended (rule 5). If it is the documented one, which says idle sessions must not block, then drop the presence checks, or base them on PTY idle time (for example the atime/mtime of /dev/pts/N, which is what w reads). Add a fixture test for "PTY open, idle 2 h, so idle".

Activity

  1. scttfrdmn commented on Oct 15, 2026

    @scttfrdmn
    ContributorAuthor

    A related point to check before fixing this. It is unverified and comes from reading the code.

    sysCountActiveSessions reads the idle column from w -h -s as fields[3], which assumes the FROM column is printed. procps-ng's w(1) says FROM is toggled by -f, and that "the default as released is for the from field to not be printed", although distributions may build it the other way. Without FROM, fields[3] is the WHAT column (-bash), and isRecentActivity treats a format it does not know as "recent". Every session would then count as active whatever its idle time, which is the same "never idle" result as the presence checks above.

    The PTY check currently hides this. If it is removed as suggested, the session parser needs a fixture for both column layouts. It would also be safer to locate the idle column structurally, by taking the field that parses as an idle time rather than a fixed index, or to read the PTY's atime directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions