deepch / RTSPtoWeb

RTSP Stream to WebBrowser
MIT License
1.27k stars 302 forks source link

"assignment to entry in nil map" error while adding new channel to a stream #308

Open sahin52 opened 1 year ago

sahin52 commented 1 year ago

Initial config.json file is like this:

.
.

"streams": {
  }
.
.

I add a stream named demo1 (I will give windows bash example): curl.exe --header "Content-Type: application/json" --request POST --data '{\"name\":\"demo1\", \"channels\":{}}' http://demo:demo@127.0.0.1:8083/stream/demo1/add Linux bash is similar, but I didn't test: curl --header "Content-Type: application/json" --request POST --data '{"name":"demo1", "channels":{}}' http://demo:demo@127.0.0.1:8083/stream/demo1/add config file becomes like this:

.
"streams": {
    "demo1": {
      "name": "demo1"
    }
  }
.

and I add a stream to this: in Windows: curl.exe --header "Content-Type: application/json" --request POST --data '{ \"name\": \"ch4\", \"url\": \"rtsp://admin:admin@{YOUR_CAMERA_IP}/uri\", \"on_demand\": false, \"debug\": false, \"status\": 0 }' http://demo:demo@127.0.0.1:8083/stream/demo1/channel/1/add in Linux (probably): curl --header "Content-Type: application/json" --request POST --data '{ "name": "ch4", "url": "rtsp://admin:admin@{YOUR_CAMERA_IP}/uri", "on_demand": false, "debug": false, "status": 0 }' http://demo:demo@127.0.0.1:8083/stream/demo1/channel/1/add

and sometimes I get this error:

2023/03/23 15:14:47 [Recovery] 2023/03/23 - 15:14:47 panic recovered:
POST /stream/demo1/channel/1/add HTTP/1.1
Host: 127.0.0.1:8083
Accept: */*
Authorization: *
Content-Length: 190
Content-Type: application/json
User-Agent: curl/7.83.1

assignment to entry in nil map
C:/Program Files/Go/src/runtime/map.go:580 (0xefa1c)
        mapassign: panic(plainError("assignment to entry in nil map"))
D:/temp/storageStreamChannel.go:267 (0x7e5c44)
        (*StorageST).StreamChannelAdd: obj.Streams[uuid].Channels[channelID] = val
D:/temp/apiHTTPChannel.go:136 (0x7bfb8d)
        HTTPAPIServerStreamChannelAdd: err = Storage.StreamChannelAdd(c.Param("uuid"), c.Param("channel"), payload)
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/context.go:174 (0x7cf098)
        (*Context).Next: c.handlers[c.index](c)
D:/temp/apiHTTPRouter.go:296 (0x7cf084)
        CrossOrigin.func1: c.Next()
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/context.go:174 (0x607ba1)
        (*Context).Next: c.handlers[c.index](c)
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/recovery.go:102 (0x607b8c)
        CustomRecoveryWithWriter.func1: c.Next()
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/context.go:174 (0x606ca6)
        (*Context).Next: c.handlers[c.index](c)
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/logger.go:240 (0x606c89)
        LoggerWithConfig.func1: c.Next()
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/context.go:174 (0x605d70)
        (*Context).Next: c.handlers[c.index](c)
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/gin.go:620 (0x6059d8)
        (*Engine).handleHTTPRequest: c.Next()
C:/Users/TEMP/go/pkg/mod/github.com/gin-gonic/gin@v1.9.0/gin.go:576 (0x60551c)
        (*Engine).ServeHTTP: engine.handleHTTPRequest(c)
C:/Program Files/Go/src/net/http/server.go:2947 (0x3eed4b)
        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
C:/Program Files/Go/src/net/http/server.go:1991 (0x3e9f66)
        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
C:/Program Files/Go/src/runtime/asm_amd64.s:1594 (0x147040)
        goexit: BYTE    $0x90   // NOP

[GIN] 2023/03/23 - 15:14:47 | 500 |     12.1846ms |       127.0.0.1 | POST     "/stream/demo1/channel/1/add"

After an error, even though you restart RtspToWeb.exe, it doesn't add the channel, I have to revert config.json to this:

"streams": {
    "demo1": {
      "channels": {
      },
      "name": "demo1"
    }
  }

and restart rtsptoweb.exe and it works again.