Skip to content

Conversation

@gbakeman
Copy link
Contributor

@gbakeman gbakeman commented Dec 4, 2025

Notable changes

  • Fixes UI becoming frozen when connection is suddenly disconnected
  • Communication timeout is now 5 seconds making broken connections detectable faster than before (timeout was about 30 seconds.) However, communication is still synchronous with the UI so WinNUT will appear to hang during any socket operations (connect, read or write).
  • Connection error handling is more consistent
  • Fixes bug where data was not available for the time it takes till the next poll.

Outline

  • Removed redundant checks during queries
  • Added comments and documentation

Common_Enums:

  • Removed "EMPTY" NUTResponse; EndOfStreamException thrown instead.

Common_Classes:

  • Adding String array to Transaction class to store split responses so split operation doesn't need to be repeated for later processing.
  • Removed extra NutError constructor

Nut_Socket:

  • Specified 5 second timeout for socket communication (outside of initial connection) so broken connections are handled faster
  • Specified protocol character encoding for the sake of exactness (doesn't necessarily change functionality)
  • Take entire string returned in VER query, rather than looking for server semver.
  • Slightly adjust order of operations in Connect subroutine
  • Adding OnSocketBroken subroutine to handle errors during Query_Data
  • Catch exceptions when reading and writing to the socket so the object can reset its state and disconnect
  • Remove unnecessary operations on response string
  • Opportunistically throw exceptions when necessary during response parsing

UPS_Device:

  • Start Update_Data timer later on in connection sequence, and retrieve a copy of the data right away.
  • Enhanced parameter checking in GetUPSVar
  • Simplified response verification
  • Combined exception handling and record the last exception
  • For Loop is only continued under specific circumstances now
  • Better error logging towards end of GetUPSVar

Closes #223

Declare a constant value of 5 seconds for communications with the NUT server (temporary patch until we have true async communication)
- Added a general description to the header of the Nut_Socket class
- Removed redundant check during query for server version (NutException or others thrown in adverse conditions)
- Entire response of VER query is accepted, rather than trying to locate the semver string specifically
Common_Enums:
- Removed "EMPTY" NUTResponse; `EndOfStreamException` thrown instead.
Common_Classes:
- Adding String array to Transaction class to store split responses so split operation doesn't need to be repeated for later processing.
- Remove extra NutError constructor
Nut_Socket:
- Remove redundant check in NETVER query since errors are thrown
- Slightly adjust order of operations in Connect subroutine
- Adding `OnSocketBroken` subroutine to handle errors during Query_Data
- Catch exceptions when reading and writing to the socket so the object can reset its state and disconnect
- Remove unnecessary operations on response string
- Opportunistically throw exceptions when necessary during response parsing
UPS_Device:
- Start Update_Data timer later on in connection sequence, and retrieve a copy of the data right away.
- Enhanced parameter checking in GetUPSVar
- Simplified response verification
- Combined exception handling and record the last exception
- For Loop is only continued under specific circumstances now
- Better error logging towards end of GetUPSVar
@gbakeman gbakeman linked an issue Dec 4, 2025 that may be closed by this pull request
@gbakeman gbakeman self-assigned this Dec 4, 2025
@gbakeman gbakeman added bug Something isn't working enhancement New feature or request labels Dec 4, 2025
@gbakeman gbakeman added this to the 2.3 Stable Release milestone Dec 4, 2025
@gbakeman gbakeman merged commit c09ddc9 into dev-2.3 Dec 6, 2025
1 check passed
@gbakeman gbakeman deleted the 223-fix-broken-socket-hang branch December 6, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not detecting lost connection in certain circumstances

2 participants