cover image



Tags

vignette

software

review

film

rationality

Automatic Logouts on Ubuntu 22.04

In a previous post I detailed the issues that arose when I upgraded my Ubuntu to 22.04 (a.k.a. Jellyfish), and gave a broad outline of how I went about fixing them. But there’s one nasty issue I left out: after the upgrade I found out that the OS would sometimes automatically log me out right after I log in. The behavior was very inconsistent. Sometimes I got logged out, sometimes I didn’t. I would have to try logging in a varying number of times, up to 6 or 7, before a log in would be accepted. The time interval between logging in and getting logged out ranged from immediately to 2 minutes. It was an annoying bug, but it was another couple of months before I decided to tackle it. Fixing the other upgrade problems took a couple of hours, but I had a feeling this one was different. I had software projects I wanted to work on, so I decided to postpone dealing with the problem.

When I finally started working on the issue, the first thing I discovered was that it doesn’t happen when I switch from Wayland to Xorg. Since Ubuntu 22.04 was Wayland’s debut as the default display server, I concluded that something broke in Wayland during the upgrade. With this conclusion in hand I turned to Google for help. A search informed me that it’s a problem which many Linux users have experienced before, but there was little in the way of solutions which relate to my specific case. A useful suggestion was trying to log in using a test user account, something which informed me that the problem was system-wide and, consequently, enabled me to rule out my user’s configuration files as the source of the problem. Another suggestion was checking my tmp directory’s permissions, but there was nothing anomalous there. Other than that the only relevant suggestion I found was the nuclear option: reinstalling the desktop environment and the gdm. The reinstallation process went smoothly, but when I tried to log in afterwards the OS logged me out again. At this point I concluded that the cause of the issue was unique to my case and that I, consequently, had to come up with a solution on my own.

I started, naturally enough, with examining the authentication log. But after poring over its records for a long time I finally came to the conclusion that there was nothing relating to the problem there. I examined the kernel log next, but the result was the same. The breakthrough came when I moved on to the syslog. When I examined the event records whose timestamps matched the time of the automatic log outs, I discovered that every time an automatic log out happens a couple of records similar to these would be present:
13 Jan 29 08:12:12 COMPUTER NAME systemd-oomd[644]: Killed /user.slice/user-1000.slice/user@1000.service/session.slice/org.gnome.Shell@wayland.service due to memory pressure for /user.slice/user-1000.slice/user@1000.service being 55.78% > 50.00% for > 20s with reclaim activity
13 Jan 29 08:12:12 COMPUTER NAME systemd[1899]: org.gnome.Shell@wayland.service: systemd-oomd killed 25 process(es) in this unit.

The cause of the problem was now clear: the “out of memory” daemon (oomd) kills a bunch of the Gnome Shell’s processes every time its swap activity exceeds 50%. The problem started after the upgrade because oomd was turned on by default in 22.04. I’m not sure why oomd didn’t cause the same problem when I tried switching to Xorg. My guess is that it’s either because the Gnome Shell’s swap activity under Xorg is always lower than 50%, or that oomd is somehow turned off when Xorg takes over as the system’s display server.

I wasn’t surprised when I found out the cause of the problem. Ever since it was made a default on Jellyfish, people have been complaining about oomd killing software processes without proper justification and without a warning. What’s different about my case is that oomd’s aggressive killing of software processes has resulted in an automatic logouts problem.

The solution was disabling oomd. Following the instructions outlined here, I executed the command:
systemctl disable --now systemd-oomd
then checked the status of the process using:
systemctl is-enabled systemd-oomd
The result was exactly what it was supposed to be:
disabled
I logged out and then logged in. To my surprise, I got automatically logged out again. The next log in attempt was successful. When I checked syslog I found the familiar records showing that oomd had, once again, killed a bunch of the Gnome Shell’s processes right before the automatic logout. I checked the status of oomd but the official verdict was that the process was still:
disabled
The oomd process was running even though its official status was “disabled”. It was time to go for a more dramatic solution, and the recommendation was using the command:
systemctl mask systemd-oomd
for which the result is:
Created symlink /etc/systemd/system/systemd-oomd.service → /dev/null.
I’m happy to say that this was the end of the automatic logout problem on my Ubuntu.

Linux has historically had a serious problem dealing with situations where the system is critically low on memory. The “Task Manager” was the brilliant solution which Microsoft’s developers came up with, in 1994, to handle situations like these. In contrast, Linux’s userspace attempt, taken a quarter of a century later, to tackle this problem turned out to be the cure that is as bad as the disease.

What about the “Year of Linux on the Desktop”? Maybe the next millennium.

Posted: 13-02-2023
Tags: software