Skip to content

IndexOutOfRange when retrieving variables #239

Description

@gbakeman

Discussed in #238

Originally posted by @r0m30rr July 3, 2026
Hello everyone! Could someone help me understand what is going on in this log that is preventing WinNUT from pulling accurate information from my Unifi UPS Tower?
image
Thanks!

Extracted text from image:

7/3/2026 1:19:53 PM [24228, Logger]: Attempt init log file: C:\Users\r0m30\AppData\Local\NUTDotNet\WinNUT Client\2.3.9492.23861\Logs\WinNUT-Client-2026-07-03.log
====History of 200 previous events ====
[1] 7/3/2026 1:18:53 PM [24228, UPS_Device]: Trying variable: battery.charge
[2] 7/3/2026 1:18:53 PM [24228, UPS_Device]: Socket or other unexpected error encountered. Expect a SocketBroken event to follow.
[3] 7/3/2026 1:18:53 PM [24228, UPS_Device]: Unable to get any UPS variable.
[4] 7/3/2026 1:18:53 PM [24228, UPS_Device]: Last exception recorded:
[5] 7/3/2026 1:18:53 PM [24228, UPS_Device]: System.IndexOutOfRangeException thrown in WinNUT-Client_Common
Message: Index was outside the bounds of the array.
at WinNUT_Client Common.Nut_Socket.Query_Data(String Query_Msg) in C:\Users\Glen\Repositories\nutdotnet\WinNUT-Client\WinNUT_V2\WinNUT-Client_Common\Nut_Socket.vb:line 185
at WinNUT_Client Common.UPS_Device.GetUPSVar(String[] varNames, Object Fallback_value, Boolean recursing) in C:\Users\Glen\Repositories\nutdotnet\WinNUT-Client\WinNUT_V2\WinNUT-Client_Common\UPS_Device.vb:line 461

Summary

WinNUT may not be correctly checking for a valid UPS before retrieving variables from the server. @Simon-CR reports that this is the behavior when an invalid UPS name is entered.

Ubiquiti Unifi UPS

A common thread appears to be the Ubiquiti Unifi UPS Tower device, which has a management system built in running the NUT server software (or a modified build thereof.) The product listing implies that this device is running UnifiOS.

Community info

Tasks

  • Verify behavior when connecting to a NUT server with an invalid UPS name entered
  • Confirm that server and protocol versions are capturing the "OK" response with the data, fix
  • Update/add documentation for Unifi Tower hardware connection config for WinNUT
    • Obtain permission from @Simon-CR to use their screenshot(s)

First connect

7/10/2026 4:18:35 PM [22272, WinNUT]: Client UPS_Connect subroutine beginning.
7/10/2026 4:18:35 PM [22272, UPS_Device]: Beginning connection: admin@192.168.1.158:3493, Name: Unifi Tower [AutoReconnect]
7/10/2026 4:18:35 PM [22272, Nut_Socket]: Attempting TCP socket connection to 192.168.1.158:3493...
7/10/2026 4:18:35 PM [22272, Nut_Socket]: Connection established and streams ready.
7/10/2026 4:18:35 PM [22272, Nut_Socket]: Gathering basic info about the NUT server...
7/10/2026 4:18:35 PM [22272, Nut_Socket]: Server version: OK Network UPS Tools upsd 2.8.0
7/10/2026 4:18:35 PM [22272, Nut_Socket]: Protocol version: OK 1
7/10/2026 4:18:35 PM [22272, Nut_Socket]: Completed gathering basic info about NUT server.
7/10/2026 4:18:35 PM [22272, UPS_Device]: Retrieving basic UPS product information...
7/10/2026 4:18:35 PM [22272, UPS_Device]: Attempting to get UPS variable with 1 alternatives.
7/10/2026 4:18:35 PM [22272, UPS_Device]: Trying variable: ups.mfr
7/10/2026 4:18:35 PM [22272, UPS_Device]: Socket or other unexpected error encountered. Expect a SocketBroken event to follow.
7/10/2026 4:18:35 PM [22272, UPS_Device]: Unable to get any UPS variable.
7/10/2026 4:18:35 PM [22272, UPS_Device]: Last exception recorded:
7/10/2026 4:18:35 PM [22272, UPS_Device]: System.IndexOutOfRangeException thrown in WinNUT-Client_Common
Message: Index was outside the bounds of the array.
at WinNUT_Client_Common.Nut_Socket.Query_Data(String Query_Msg) in C:\Users\Glen\Repositories\nutdotnet\WinNUT-Client\WinNUT_V2\WinNUT-Client_Common\Nut_Socket.vb:line 185
at WinNUT_Client_Common.UPS_Device.GetUPSVar(String[] varNames, Object Fallback_value, Boolean recursing) in C:\Users\Glen\Repositories\nutdotnet\WinNUT-Client\WinNUT_V2\WinNUT-Client_Common\UPS_Device.vb:line 461

7/10/2026 4:18:35 PM [22272, Logger]: Exception report complete.
7/10/2026 4:18:35 PM [22272, UPS_Device]: Returning fallback value.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions