toxuin / alarmserver

IP Camera Alarm Server to MQTT
MIT License
145 stars 34 forks source link

Panic: slice bounds out of range #26

Open dr3amr opened 1 year ago

dr3amr commented 1 year ago

Hi,

First, thanks for this, been looking for something like this to profit from embedded AI / Human detection features (instead of frigate which is cpu hog without Google Coral) outside of chinese apps / servers (I would limit internet acces to camera) and except for bellow everything works as expected.

I get bellow error few times a day and the container crashes:

panic: runtime error: slice bounds out of range [-1:]
goroutine 36 [running]:
github.com/toxuin/alarmserver/servers/hisilicon.(*Server).handleTcpConnection(0xc000184180, {0x997eb8?, 0xc00000e030})
    /tmp/app/servers/hisilicon/server.go:61 +0x805
created by github.com/toxuin/alarmserver/servers/hisilicon.(*Server).Start.func2
    /tmp/app/servers/hisilicon/server.go:126 +0x105

I have only debug:true, hisilicon and mqtt enabled. What can I do? I see there is a .handleTcpConnection method involved, which connection alarm->mqtt or camera->alarm?

toxuin commented 1 year ago

This is a bug, thank you for finding it! It happens when camera sends a string that is not a valid JSON and because there is not sufficient checking for such condition right now - it crashes the app, while it should just be ignored. What camera is doing that?

dr3amr commented 1 year ago

I have 4x Misecu 5mp PoE cameras like bellow. Wifi is unstable but seems also PoE is unstable for these cameras. This seems like a generic camera as I saw it with different brands on Aliexpress. The video quality is good. https://a.aliexpress.com/_EI9XKcr

dr3amr commented 1 year ago

@toxuin any ideea if this is hard to implement / fix?

dr3amr commented 1 year ago

At the moment I have setup a rule to automatically restart the container on failure thus it is almost always available and listening for "alarms" from the AI cameras. I have an automation to turn on outside lights on human detection thus the alarm server is useful, as at the moment I do not have to use Frigate which melts the CPU as I have no Coral to help.

aguscaba commented 1 year ago

This is a bug, thank you for finding it! It happens when camera sends a string that is not a valid JSON and because there is not sufficient checking for such condition right now - it crashes the app, while it should just be ignored. What camera is doing that?

Hi @toxuin in my case the one who is sending non valid JSON stuff is the load balancer, in order to have my alarm server always up I setup a LB in front of my alarm server and created 2 of them (alarm servers) but instantally they went down :(