Repository navigation
Fix/session sockets - #1717
Fix/session sockets#1717
Conversation
Register each user’s Wayland listener at startup and compositor recovery. - Reuse repeated registrations of the same listener and track its D-Bus owner so disconnects release only the matching user socket. Duplicate received descriptors for WSocket ownership and synchronize child socket enablement with the owning Session. Log: preserve user Wayland sockets across desktop switches PMS: TASK-398167 Influence: user switching, Wayland activation and session teardown
Relogin with a new session ID replaces a desktop and its protocol globals. User socket registration and logout also need a test that runs independently of output scaling. - Repeat same-account relogin with new session IDs and check that retiring the old session preserves activation of the replacement and each session exposes its own globals. - Exercise repeated listener registration, owner handover and listener replacement through D-Bus with live Wayland clients. - Verify logout closes registered and descendant socket clients while leaving an unrelated session connected. Keep registry isolation and socket teardown observable across session transitions. Session registry and user socket integration tests. Log: cover relogin isolation and user socket lifecycle PMS: TASK-398167 Influence: same-user relogin, Wayland registry isolation and socket teardown
Reviewer's GuideData structuresAdd a Session signal announcing that its clients have closed, so user-socket cleanup can follow Session teardown.
APIExpose private Treeland cleanup for releasing a user’s Wayland socket only when it is still the expected socket.
ImplementationRegister and reuse user Wayland sockets with D-Bus owner tracking, Session-synchronized enablement, and guarded cleanup on owner loss or client shutdown.
Make systemd socket activation retry failed Wayland registration and environment updates, and reset activation state across compositor recovery and Session changes.
Log a warning when activating a user’s desktop session fails.
Stop changing registered socket enablement when the displayed current user changes; it now follows the owning Session.
DocumentationDocument the new relogin isolation and standalone user-socket lifecycle coverage in the protocol test index and guide.
TestsExercise same-account relogin with new Session IDs and verify old Session cleanup does not disturb the replacement’s activation or registry isolation.
Add an independent D-Bus and Wayland integration test for socket registration, owner handover, Session enablement, replacement, and logout cleanup.
Other changesFiles not grouped.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 7 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/core/treeland.cpp" line_range="600" />
<code_context>
+ }
+ qCDebug(lcTlDBus) << "Releasing Wayland socket for user" << user
+ << "with" << socket->clients().size() << "clients";
+ account->setWaylandSocket(nullptr);
+}
</code_context>
<issue_to_address>
**Socket is destroyed inside its callback**
When the current owner disconnects or its Session shuts down, `clientsClosed` and `serviceUnregistered` invoke `releaseUserWaylandSocket` through the socket as the connection context. Clearing the account’s last shared reference destroys that socket before the callback returns, so Qt continues signal delivery with a deleted receiver and logout or owner disconnect can crash the compositor.
Defer releasing the final socket reference until after the active signal callback returns.
</issue_to_address>
### Comment 2
<location path="src/core/treeland.cpp" line_range="600" />
<code_context>
+ }
+ qCDebug(lcTlDBus) << "Releasing Wayland socket for user" << user
+ << "with" << socket->clients().size() << "clients";
+ account->setWaylandSocket(nullptr);
+}
</code_context>
<issue_to_address>
**Descendant listeners outlive logout**
When a descendant listener exists without connected clients when the user socket is released, `releaseUserWaylandSocket` clears the account’s shared pointer without explicitly retiring descendant listeners. A descendant with no connected clients is not collected by `Session::closeClients`, so its listener remains registered after the owning user socket is released and can accept connections after logout.
Track and close/remove descendant listeners as part of releasing the user socket, including descendants with no connected clients.
</issue_to_address>
### Comment 3
<location path="src/core/treeland.cpp" line_range="617" />
<code_context>
+ qCWarning(lcTlDBus) << "Cannot resolve Wayland socket owner" << owner << uid.error();
+ return false;
+ }
+ const auto session = d->server->sessionManager()->sessionForUid(uid.value());
WSocket *sessionSocket = session ? session->socket() : nullptr;
- if (!sessionSocket)
</code_context>
<issue_to_address>
**Wrong session owns user listener**
When the account has multiple live sessions with the same UID, `sessionForUid()` returns the first matching session without checking which same-UID session is active. `ActivateWayland()` therefore parents the user listener to that session, so another concurrent or not-yet-removed login for the same account gets the wrong enablement and shutdown lifecycle.
Select the session corresponding to the activation request or explicitly define and enforce a single-session-per-UID policy before associating the listener.
</issue_to_address>
### Comment 4
<location path="tests/protocols/session-isolation/socket-lifecycle-setup.cpp" line_range="50" />
<code_context>
+ if (!socket.create(path))
+ return false;
+ qstrncpy(endpoint.name, path.toUtf8().constData(), sizeof(endpoint.name));
+ endpoint.fd = socket.socketFd();
+ return true;
+}
</code_context>
<issue_to_address>
**Socket lifecycle test cannot register**
When the fixture and C client run in separate processes, as in the protocol-test framework, the fixture writes the compositor process’s descriptor number into shared test state, and the C client passes that number to `QDBusUnixFileDescriptor` without receiving the descriptor itself. The D-Bus call therefore sends an invalid or unrelated client-process descriptor, so registration fails and the lifecycle test cannot exercise its claimed scenarios.
Transfer the listening descriptor to the C client with descriptor-passing support, or perform the D-Bus registration from the fixture process.
Also at `tests/protocols/session-isolation/socket-lifecycle-setup.cpp:117`.
</issue_to_address>
### Comment 5
<location path="src/systemd-socket.cpp" line_range="97" />
<code_context>
+ ? QStringLiteral("compositor rejected request")
+ : activated.error().message();
+ qCWarning(lcSdSocket) << "Failed to activate Wayland socket:" << reason;
+ scheduleActivateRetry();
return;
}
</code_context>
<issue_to_address>
**Persistent failures trigger rapid retries**
When the compositor or activation-environment D-Bus service remains unavailable, `scheduleActivateRetry()` schedules another activation after every failed D-Bus call; the timer clears the pending flag before calling `activate()` again, so a persistently unavailable compositor or activation-environment service causes repeated calls and warning logs until the dependency recovers.
Use a bounded or increasing retry delay and rate-limit repeated failure logs while continuing to retry for recovery.
</issue_to_address>
### Comment 6
<location path="tests/protocols/session-isolation/setup.cpp" line_range="302" />
<code_context>
+ sessionB = manager->sessionForId(id);
+ const bool previousInactive = !previous->isActive();
+ // Late cleanup of the old object must not remove or deactivate the new one.
+ manager->removeSession(previous);
+ previous.reset();
+ if (!sessionB || !previousInactive || !retired.expired()
</code_context>
<issue_to_address>
**Late cleanup is never exercised**
When each relogin iteration replaces the existing session for the same username, when `updateActiveUserSession(username, id)` replaces the existing session, `session_test_logout_relogin` calls `manager->removeSession(previous)` at `setup.cpp:302` only after `ensureSession` has already removed and shut down that session. The second call returns at the `isShuttingDown()` guard, so the active-session assertions pass without exercising delayed cleanup against the replacement.
Arrange for the old session’s cleanup to be genuinely deferred until after the replacement is created, then invoke and assert that cleanup.
</issue_to_address>
### Comment 7
<location path="src/core/treeland.cpp" line_range="686" />
<code_context>
});
+ // Client cleanup needs the socket ancestry to identify security-context descendants.
+ connect(session.get(), &Session::clientsClosed, socket.get(),
+ [this, user, expected = socket.get()] { releaseUserWaylandSocket(user, expected); });
+ qCDebug(lcTlDBus) << "Registered Wayland socket for user" << user
</code_context>
<issue_to_address>
**Session cleanup uses forwarding lambda**
When `Session::clientsClosed` is connected, the `clientsClosed` lambda only forwards to `releaseUserWaylandSocket(user, expected)`, contrary to the member-function-pointer guidance; the signal connection remains a forwarding lambda.
Use a member-function-pointer slot for this connection, keeping the required user and socket context in the receiving object.
</issue_to_address>|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Groveer, zorowk The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
#1654
Summary by Sourcery
Stabilize per-user Wayland socket activation and cleanup across session changes, owner handoffs, and logout.
Bug Fixes:
Enhancements:
Documentation:
Tests: