Skip to content

NUT-Monitor: Add automatic reconnection mechanism for Qt5 and Qt6#3523

Open
developersorli wants to merge 1 commit into
networkupstools:masterfrom
developersorli:nut-monitor-reconnect
Open

NUT-Monitor: Add automatic reconnection mechanism for Qt5 and Qt6#3523
developersorli wants to merge 1 commit into
networkupstools:masterfrom
developersorli:nut-monitor-reconnect

Conversation

@developersorli

Copy link
Copy Markdown

Summary

This PR adds an automatic reconnection mechanism to NUT-Monitor-py3qt5 and NUT-Monitor-py3qt6. When the connection to the NUT server is lost (e.g., after system suspend/resume, network interruption, or NUT server restart), the client will automatically attempt to reconnect.

Changes

  1. Reconnection logic in gui_updater.__update():

    • Detects connection errors via specific exceptions
    • Stops the polling timer
    • Schedules reconnection attempt after 2 seconds
  2. New __attempt_reconnect() method:

    • Gets connection parameters from the current GUI state
    • Properly tears down old PyNUTClient instance (closes telnet connection)
    • Creates new connection and verifies UPS availability
    • Restores GUI state and resumes polling
  3. __reconnect_attempted flag - prevents multiple simultaneous attempts

  4. Proper exception handling:

    • socket.error - network/socket errors
    • ConnectionError - Python 3 built-in connection errors
    • EOFError - end of file / connection closed
    • OSError - operating system errors
    • PyNUT.PyNUTError - NUT protocol errors
  5. Proper teardown of old connection handler:

    • Closes underlying telnet connection
    • Deletes old handler reference
  6. was_online flag - tracks connection state changes

Testing

  • Qt5: ✅ Fully tested and confirmed working

    • System suspend/resume cycles
    • Network disconnection/reconnection
    • NUT server restart
    • Authentication and non-authentication modes
  • Qt6: ✅ Fully tested and confirmed working

    • Same tests performed as Qt5
    • All functionality verified

Files Modified

  • scripts/python/app/NUT-Monitor-py3qt5.in
  • scripts/python/app/NUT-Monitor-py3qt6.in

Related Issues

Closes #3509

Notes for Reviewers

  • Both versions use the same reconnection logic
  • Both versions have been tested and confirmed working
  • The implementation only affects the Qt versions, not GTK2 (Python 2, obsolete)
  • The PyNUTClient instance is properly cleaned up before reconnection

- Add automatic reconnection when connection to NUT server is lost
- Implement proper teardown of old PyNUTClient instances
- Use specific exceptions (socket.error, ConnectionError, EOFError, OSError, PyNUT.PyNUTError)
- Prevent multiple simultaneous reconnection attempts
- Add 'was_online' flag to track connection state changes
- Tested and confirmed working on both Qt5 and Qt6

Closes: networkupstools#3509
Signed-off-by: Programer <developer.sorli@gmail.com>
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

A ZIP file with standard source tarball and another tarball with pre-built docs for commit 1d157f9 is temporarily available: NUT-tarballs-PR-3523.zip.

@AppVeyorBot

Copy link
Copy Markdown

Build nut 2.8.5.4914-master completed (commit 572b34b736 by @developersorli)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NUT-Monitor-py3qt5: Add D-Bus sleep handler for automatic reconnect after system wake-up

2 participants