OktopUSP/oktopus

Resilient USP info handler

Opened this issue · 1 comments

Resilient USP info handler

In the process of operation, we found a situation where Oktopus stops functioning when receiving an incorrect USP message from an agent, namely:
GET_RESP on a GET Device.Deviceinfo request.
The error causes the adapter container to crash with the error:
2024/07/22 08:39:58 info.go:15: Device proto::puma7-00:50:f1:20:00:53 info, mtp: mqtt
panic: runtime error: index out of range [0] with length 0
goroutine 55 [running]:
[github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/events/handler.parseDeviceInfoMsg({0xc0000f042c](http://github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/events/handler.parseDeviceInfoMsg(%7B0xc0000f042c), 0x1e}, {0x40e7fb?, 0xc2490a?}, {0xc0004c0000, 0x2e8})
/app/internal/events/handler/info.go:52 +0x465
[github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/events/handler.(*Handler).HandleDeviceInfo(0xc0000ca1e0](http://github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/events/handler.(*Handler).HandleDeviceInfo(0xc0000ca1e0), {0xc0000f042c, 0x1e}, {0xc0000f0420, 0x2f}, {0xc0004c0000, 0x2e8} , {0xa2650c, 0x4}, ...)
/app/internal/events/handler/info.go:16 +0x20e
github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/events.StartEventsListener.func1()
/app/internal/events/events.go:55 +0x486
created by github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/events.StartEventsListener in goroutine 1
/app/internal/events/events.go:26 +0x1e5
We found the following explanation: in the module oktopus/backend/services/mtp/adapter/internal/events/handler/info.go (and in the new version it is oktopus/backend/services/mtp/adapter/internal/events/usp_handler
/info.go) an error occurs in the parsing process
device.Vendor = msg.ReqPathResults[0].ResolvedPathResults[0].ResultParams[“Manufacturer”]
device.Model = msg.ReqPathResults[1].ResolvedPathResults[0].ResultParams[“ModelName”]
device.Version = msg.ReqPathResults[2].ResolvedPathResults[0].ResultParams[“SoftwareVersion”]
device.ProductClass = msg.ReqPathResults[4].ResolvedPathResults[0].ResultParams[“ProductClass”]
Since the object msg.ReqPathResults[0].ResolvedPathResults[0] takes the value nil
In our opinion, it would be useful to add handling of such an exception to the code, as it would protect the controller and other users from incorrect behavior of one of the agents.
If necessary, we can try to provide more detailed information.
Sincerely, Oleksandr.