csd-power suspends again ~0.3–1.3 s after lid-open resume (stale lid-closed state acted upon post-resume)

Open
#483 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, linux
Domain
desktop

Research direction

Start in plugins/power/csd-power-manager.c, reading do_lid_closed_action() and lid_close_safety_timer_cb() alongside handle_resume_actions(); the reporter could not pin the exact call site, so trace every path that calls Manager.Suspend() on the session bus. Read #480 and #466 for the same function's other stale-state paths, then add a lid-state re-check (up_client_get_lid_is_closed()) before suspending. Done means a lid-close/resume cycle no longer produces the spurious second suspend in the journal, verified over several S3 cycles.

Written by the indexing model from the issue text.

Description

Summary

After waking from lid-close suspend by opening the lid, csd-power (by elimination, the only session process that calls login1 Suspend) initiates a second suspend ~0.3–1.3 s after resume, apparently acting on a stale lid-closed notification that was generated at suspend time and only delivered after thaw. Visually: the panel lights up on lid open, then goes black ~1 s later; a second power-button press is needed to wake, after which the problem never recurs for that cycle.

systemd-logind's lid-close suspend itself works correctly. Suspending via the power button and waking is completely unaffected (no stale lid state exists on that path).

System

  • Linux Mint 22.3 (Zena), Cinnamon (X11), cinnamon-settings-daemon 6.6.4+zena
  • systemd 255.4-1ubuntu8.18, kernel 7.0.0-34-generic, HP notebook (Intel UHD 620 + Radeon PRO WX 3100)
  • /sys/power/mem_sleep = s2idle [deep] (S3), all logind.conf defaults (HandleLidSwitch=suspend)
  • lid-close-ac-action = lid-close-battery-action = suspend (stock defaults), sleep-inactive-* = 0, no external monitor connected

Reproduction

  1. Default power settings, close the lid (machine suspends within ~0.5 s via logind).
  2. Wait > a few seconds, open the lid.
  3. Panel turns on, then goes black ~1 s later — machine has re-suspended.
  4. Press the power button: machine wakes and stays awake.

Happens 3/3 lid cycles observed. Never happens with power-button suspend/wake, and the spurious re-suspend consumes itself: the wake after it is always clean.

Journal timeline (short-precise, one cycle; identical pattern in all three)

07:44:10.520  systemd-logind: Lid closed.
07:44:10.529  systemd-logind: Suspending...
07:44:10.977  kernel: PM: suspend entry (deep)
                      [10 h asleep; lid physically opened during sleep]
09:05:52.942  systemd-logind: Lid opened.                <- wake, panel lights up
09:05:53.226  systemd-sleep: System returned from sleep operation 'suspend'.
09:05:53.312  systemd-logind: Operation 'suspend' finished.
09:05:53.705  systemd-logind: The system will suspend now!   <- SPURIOUS
09:05:54.128  kernel: PM: suspend entry (deep)               <- screen goes black
   ~09:06:05  (user presses power button)
09:06:06.014  kernel: PM: suspend exit                       <- desktop restored, stays up

Other two cycles: resume → spurious suspend delays of +0.31 s (Nov 14 20:24) and +0.89 s (Nov 15 07:26).

Analysis

  • Kernel/GPU resume is clean (PM: suspend exit without errors, both i915 panel restore and the following manual wake resume fine) — not a resume failure.
  • The spurious suspend is initiated by systemd-logind itself (verbose journal: CODE_FILE=src/login/logind-wall.c, CODE_FUNC=warn_wall, ACTION=suspend).
  • logind's own lid/button paths are excluded: the HoldoffTimeoutSec window (default 30 s) is armed at suspend start and CLOCK_MONOTONIC demonstrably freezes during S3 (journal monotonic field: Δmonotonic = 3.5 s while Δwall = 10.4 h across this cycle), so the window was still active at resume+0.76 s; manager_handle_action() consults it for INHIBIT_HANDLE_LID_SWITCH. No button events were logged either.
  • That leaves the D-Bus Manager.Suspend() method, which is not gated by the holdoff window. The only process on this system known to call it is csd-power (it demonstrably races logind's suspend: .xsession-errors contains csd-power-WARNING: Unable to inhibit suspend: OperationInProgress from the lid-close path).
  • Best-fit mechanism: the lid-state-change notification (notify::lid-is-closed via UPower, or the dbus delivery thereof) generated around suspend entry is still in transit when the system freezes; after thaw it reaches csd-power, which runs do_lid_closed_action() without validating that the lid is now open, and suspends. The 0.3–1.3 s variance matches post-thaw dbus dispatch latency.
  • This also explains the "screen lights up, then goes black" experience: the resume completed successfully, the spurious suspend arrives ~1 s later.

I could not 100% pin the exact csd-power call site statically (resume-time suspend is not visible in csd-power's handle_resume_actions()), so the transport/stale-signal detail above is inference; the logind-side exclusion of all other triggers is measured, not inferred.

Related issues

  • #480 — same defect pattern: do_lid_closed_action() executes without re-checking current lid state (there, blocked by the synchronous lock-screen call; here, blocked by the S3 freeze of the transport). A fix that validates lid state at execution time should close both.
  • #466 — the 30 s lid-close safety timer path of the same function.
  • GNOME side: gnome-settings-daemon#903 — same bug class ("state saved before suspend acted upon after resume"), fixed upstream in gsd 50.

Workaround

gsettings set org.cinnamon.settings-daemon.plugins.power lid-close-ac-action 'nothing'
gsettings set org.cinnamon.settings-daemon.plugins.power lid-close-battery-action 'nothing'

logind keeps handling lid-close suspend (its HandleLidSwitch=suspend is what actually suspends anyway in this configuration), and do_power_action_type() becomes a no-op for the lid path, so the stale post-resume action can no longer suspend. Cost: loses csd-power's external-monitor lid policy and lid sound. (Applied on the affected machine; reporter is verifying the wake is now clean.)

Suggested fix

  • Re-read the current lid state (up_client_get_lid_is_closed() or logind's LidClosed) immediately before executing the suspend in do_lid_closed_action() / lid_close_safety_timer_cb(), and drop the action if it is stale; or
  • Discard lid events/notifications whose timestamp predates the last PrepareForSleep(false).
Dominant language
C
Stars
70
Forks
81
Avg merge
2d 7h
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from linuxmint/cinnamon-settings-daemon

All issues in linuxmint/cinnamon-settings-daemon

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.