Bug 2539831

Summary: nut-monitor: NUT-Monitor-py3qt6 spins at 100% CPU and UI freezes forever after upsd closes the connection (fixed upstream in master, not in 2.8.5)
Product: [Fedora] Fedora Reporter: Josh Cantore <ykne-copr>
Component: nutAssignee: Michal Hlavinka <mhlavink>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 44CC: cra, epel-packagers-sig, james, jonathan, mhlavink, orion, scott
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: nut-2.8.5-9.fc46 nut-2.8.5-9.fc44 nut-2.8.5-9.fc43 nut-2.8.5-9.fc45 Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2026-10-07 15:22:11 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Josh Cantore 2026-09-23 22:42:33 UTC
Description of problem:
NUT-Monitor (Qt6) hangs with one core pegged at 100% and a completely unresponsive
window after the NUT server closes its connection. The app never recovers and has to be
killed. In my case it ran for 8h37m and used 356 CPU-minutes before I noticed.

Version-Release number of selected component:
nut-monitor-2.8.5-8.fc44.x86_64  (python3.14, Fedora 44)

How reproducible:
Always. First seen in the wild (connection dropped some time during the day), then
reproduced on demand by stopping nut-server while NUT-Monitor was connected.

Steps to Reproduce:
1. Start nut-server and run NUT-Monitor-py3qt6, connect to a UPS on localhost.
2. Wait for it to start polling (it polls once per second).
3. systemctl stop nut-server  (upsd closes the client socket).

Actual results:
NUT-Monitor's main thread loops forever. The window stops responding and one core
is at ~99% CPU.

strace of the stuck process (about 37,000 iterations per second):
  recvfrom(22, "", 50, 0, NULL, NULL)     = 0
  poll([{fd=22, events=POLLIN}], 1, 5000) = 1 ([{fd=22, revents=POLLIN|POLLERR|POLLHUP}])
  recvfrom(22, "", 50, 0, NULL, NULL)     = 0
  poll([{fd=22, events=POLLIN}], 1, 5000) = 1 ([{fd=22, revents=POLLIN|POLLERR|POLLHUP}])
  ...
strace -c over 5 seconds: 183712 poll calls, 183712 recvfrom calls, nothing else.
Only the main thread was busy; the other threads (Qt/D-Bus/GLib) were idle in poll/futex.
The upsd side was healthy at the time (nut-server active, upsc backups returned
ups.status: OL, battery.charge: 100).

Expected results:
When the server closes the connection, NUT-Monitor should notice, show an error in the status
bar (its existing "Error from ..." handler), and stay responsive.

Additional info / analysis:
The cause is in /usr/lib/python3.14/site-packages/PyNUT.py, PyNUTClient.__read_until():

    def __read_until(self, finished_reading_data):
        data = self.__recv_leftover
        while True:
            data_end_index = data.find(finished_reading_data)
            if data_end_index == -1:
                data += self.__srv_handler.recv(50)
            else:
                break

When the peer closes the socket, recv() returns b"" (EOF) forever. Nothing is appended, the
terminator is never found, and the loop never exits. It also never raises, so the
"except:" in the GUI's updater (NUT-Monitor-py3qt6, gui_updater.__update) is never reached.
Because the polling is done from a QTimer on the GUI thread, the whole UI blocks.

Upstream status:
This is already fixed in upstream master by commit 3e675fedbbec7f8a38b477e20bb85f00d9a42226
("PyNUT.py.in: __read_until(): handle the case of un-received chunk [#3509]", Jim Klimov,
2026-07-19), which is after the v2.8.5 tag (2026-04-07):

    -                data += self.__srv_handler.recv(50)  # nut_telnetlib.py uses 50
    +                chunk = self.__srv_handler.recv(50)  # nut_telnetlib.py uses 50
    +                if not chunk:
    +                    raise EOFError("Connection closed by server")
    +                data += chunk

Upstream issue #3509 (NUT-Monitor: no automatic reconnect after connection loss) is closed;
that issue is about reconnecting, and this hang was not reported there. I found no upstream
or Fedora Bugzilla report of the 100% CPU / frozen UI symptom itself. Searches done:
Fedora Bugzilla (component nut, nut-monitor, NUT-Monitor, PyNUT) and
github.com/networkupstools/nut issues and PRs (NUT-Monitor, PyNUT, read_until, CPU, hang).

Request:
Please backport 3e675fedbb to the Fedora nut package (F44 and rawhide, and F43 if it has
the same PyNUT.py). It is a 4-line change to PyNUT.py, with no new dependencies. With
it, the GUI's existing except: branch reports the lost connection instead of hanging.
(Automatic reconnect is a separate upstream change and is not needed to fix the hang.)

Comment 1 Fedora Update System 2026-10-07 15:18:30 UTC
FEDORA-2026-a4e9e7e419 (nut-2.8.5-9.fc46) has been submitted as an update to Fedora 46.
https://bodhi.fedoraproject.org/updates/FEDORA-2026-a4e9e7e419

Comment 2 Fedora Update System 2026-10-07 15:22:11 UTC
FEDORA-2026-a4e9e7e419 (nut-2.8.5-9.fc46) has been pushed to the Fedora 46 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 3 Fedora Update System 2026-10-07 16:12:47 UTC
FEDORA-2026-c2f2eb1508 (nut-2.8.5-9.fc44) has been submitted as an update to Fedora 44.
https://bodhi.fedoraproject.org/updates/FEDORA-2026-c2f2eb1508

Comment 4 Fedora Update System 2026-10-07 16:12:48 UTC
FEDORA-2026-f8a24f0b0f (nut-2.8.5-9.fc43) has been submitted as an update to Fedora 43.
https://bodhi.fedoraproject.org/updates/FEDORA-2026-f8a24f0b0f

Comment 5 Fedora Update System 2026-10-08 02:08:57 UTC
FEDORA-2026-b5f99ecfb6 has been pushed to the Fedora 45 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2026-b5f99ecfb6`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2026-b5f99ecfb6

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 6 Fedora Update System 2026-10-08 02:32:15 UTC
FEDORA-2026-c2f2eb1508 has been pushed to the Fedora 44 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2026-c2f2eb1508`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2026-c2f2eb1508

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 7 Fedora Update System 2026-10-08 03:01:34 UTC
FEDORA-2026-f8a24f0b0f has been pushed to the Fedora 43 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2026-f8a24f0b0f`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2026-f8a24f0b0f

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 8 Fedora Update System 2026-10-16 16:33:17 UTC
FEDORA-2026-c2f2eb1508 (nut-2.8.5-9.fc44) has been pushed to the Fedora 44 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 9 Fedora Update System 2026-10-16 16:49:00 UTC
FEDORA-2026-f8a24f0b0f (nut-2.8.5-9.fc43) has been pushed to the Fedora 43 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 10 Fedora Update System 2026-10-31 18:32:10 UTC
FEDORA-2026-b5f99ecfb6 (nut-2.8.5-9.fc45) has been pushed to the Fedora 45 stable repository.
If problem still persists, please make note of it in this bug report.