search: panic when certain devices selected

Issue #153 resolved
Trek Hopton created an issue

It has been found that when certain devices are selected from the drop-down on the search page, it triggers a panic on the back end, this is the log output from vidgrind:

2021-10-26 05:57:27 default[7] 2021/10/26 05:57:26 http: panic serving 127.0.0.1:34563: runtime error: index out of range [0] with length 0 goroutine 179 [running]: net/http.(*conn).serve.func1(0xc000457360) /usr/local/go/src/net/http/server.go:1801 +0x147 panic(0xd5a0e0, 0xc0005f78a0) /usr/local/go/src/runtime/panic.go:975 +0x47a bitbucket.org/ausocean/iotsvc/iotds.putMtsPin(...) /layers/google.go.gomod/gopath/pkg/mod/bitbucket.org/ausocean/iotsvc@v0.2.25/iotds/mtsmedia.go:547 bitbucket.org/ausocean/iotsvc/iotds.ToMID(0xc0005f7300, 0x11, 0x0, 0x0, 0xe04c000006) /layers/google.go.gomod/gopath/pkg/mod/bitbucket.org/ausocean/iotsvc@v0.2.25/iotds/mtsmedia.go:534 +0xac main.searchHandler(0xed6c80, 0xc00062a000, 0xc0006c8000) /layers/google.go.appengine_gomod/srv/search.go:220 +0x11f5 net/http.HandlerFunc.ServeHTTP(0xe0dd88, 0xed6c80, 0xc00062a000, 0xc0006c8000) /usr/local/go/src/net/http/server.go:2042 +0x44 net/http.(*ServeMux).ServeHTTP(0x13869a0, 0xed6c80, 0xc00062a000, 0xc0006c8000) /usr/local/go/src/net/http/server.go:2417 +0x1ad net/http.serverHandler.ServeHTTP(0xc0003890a0, 0xed6c80, 0xc00062a000, 0xc0006c8000) /usr/local/go/src/net/http/server.go:2843 +0xa3 net/http.(*conn).serve(0xc000457360, 0xed8980, 0xc000085740) /usr/local/go/src/net/http/server.go:1925 +0x8ad created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2969 +0x36c

And this is the response you see in the browser: 502 Bad Gateway nginx

The specific actions which triggered an instance of this bug are; selecting AusOcean-Willunga as the site, going to the search page, and selecting “TreatmentTest” from the device dropdown.

Note: while fixing this issue, the device TreatmentTest can be deleted if necessary since it is no longer in use.

Comments (2)

  1. Saxon Milton

    This happens when a device is selected for search that does not have any input pins, i.e. no pins for searching on. SearchHandler calls iotds.ToMID with Sd.Pn == ““, then ToMID calls putMtsPin with the same empty pin. Then inside putMtsPin, we try to index the empty string; this is where the panic happens. We should check that sd.Pn is not empty, and if it is then display an error message i.e. “searching only available for devices with input pins”.

  2. Log in to comment