krakend / krakend-amqp

AMQP compatible backend for the KrakenD framework
https://www.krakend.io
Apache License 2.0
10 stars 16 forks source link

Panic when host is not defined #1

Closed taik0 closed 4 years ago

taik0 commented 5 years ago

When a host is not defined for and endpoint, the middleware will throw a panic since it's assuming all endpoints will have a host backend defined (and it should).

Config example:

{
  "version": 2,
  "extra_config": {},
  "timeout": "3000ms",
  "cache_ttl": "300s",
  "output_encoding": "json",
  "name": "testing",
  "endpoints": [
    {
      "endpoint": "/new2",
      "method": "GET",
      "extra_config": {},
      "output_encoding": "json",
      "concurrent_calls": 1,
      "backend": [
        {
          "url_pattern": "/v1/employees",
          "encoding": "json",
          "sd": "static",
          "extra_config": {}
        }
      ]
    }
  ]
}

Error:

[GIN-debug] GET    /new1                     --> github.com/devopsfaith/krakend/router/gin.CustomErrorEndpointHandler.func1 (3 handlers)
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/devopsfaith/krakend-amqp.backendFactory.initConsumer(0x24c9d80, 0xc0000aa040, 0x24d7080, 0xc000331a40, 0xc0001adbf0, 0xc0004a9530, 0xc000570790, 0x24c9d80, 0xc0000aa040, 0xc0003e1300, ...)
    /go/pkg/mod/github.com/devopsfaith/krakend-amqp@v0.0.0-20190315181526-5f14dc177694/consumer.go:28 +0x159d
github.com/devopsfaith/krakend-amqp.backendFactory.New(0x24c9d80, 0xc0000aa040, 0x24d7080, 0xc000331a40, 0xc0001adbf0, 0xc0004a9530, 0xc000570790, 0xc0003e1300, 0x100)
    /go/pkg/mod/github.com/devopsfaith/krakend-amqp@v0.0.0-20190315181526-5f14dc177694/client.go:35 +0x7a
lbn commented 4 years ago

FYI the config above still fails with a panic. I have not been able to get krakend to start without panicking using a simple config created in the builder either.

Here is the exception with the same config on 1.1.1:

./krakend run --config krakend.json                                                                                              
Parsing configuration file: krakend.json                                                                                               
2020/06/08 13:23:21  ERROR: unable to create the gologging logger: getting the extra config for the krakend-gologging module
2020/06/08 13:23:21  ERROR: unable to create the GELF writer: getting the extra config for the krakend-gelf module
2020/06/08 13:23:21  INFO: Listening on port: 8080                                                                                                                                                                                                                            
2020/06/08 13:23:21  DEBUG: creating a new influxdb client
2020/06/08 13:23:21  DEBUG: no config for the influxdb client. Aborting
2020/06/08 13:23:21  WARNING: influxdb: unable to load custom config
2020/06/08 13:23:21  WARNING: opencensus: no extra config defined for the opencensus module
2020/06/08 13:23:21  WARNING: building the etcd client: unable to create the etcd client: no config
2020/06/08 13:23:21  DEBUG: no config for the bloomfilter
2020/06/08 13:23:21  WARNING: bloomFilter: no config for the bloomfilter
2020/06/08 13:23:21  WARNING: no config present for the httpsecure module
2020/06/08 13:23:21  DEBUG: lua: no extra config
2020/06/08 13:23:21  DEBUG: botdetector middleware:  no config defined for the module
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/devopsfaith/krakend-amqp.backendFactory.initProducer(0x2576740, 0xc0003704c0, 0x2582e20, 0xc000485580, 0xc000397490, 0xc00031eb40, 0xc0004dbf60, 0x2576740, 0xc0003704c0, 0xc0000a4400, ...)
        /go/pkg/mod/github.com/devopsfaith/krakend-amqp@v1.1.0/producer.go:46 +0x86c
github.com/devopsfaith/krakend-amqp.backendFactory.New(0x2576740, 0xc0003704c0, 0x2582e20, 0xc000485580, 0xc000397490, 0xc00031eb40, 0xc0004dbf60, 0xc0000a4400, 0xc0006dea60)
        /go/pkg/mod/github.com/devopsfaith/krakend-amqp@v1.1.0/client.go:39 +0xe4
github.com/devopsfaith/krakend-lambda.BackendFactoryWithInvoker.func1(0xc0000a4400, 0x0)
        /go/pkg/mod/github.com/devopsfaith/krakend-lambda@v0.0.0-20200123123306-cce9724ca461/backend.go:51 +0x169
github.com/devopsfaith/krakend-cel.BackendFactory.func1(0xc0000a4400, 0xc000064700)
        /go/pkg/mod/github.com/devopsfaith/krakend-cel@v0.0.0-20190502130550-d6872fd4f97e/proxy.go:41 +0x59
github.com/devopsfaith/krakend-lua/proxy.BackendFactory.func1(0xc0000a4400, 0x22b5e30)
        /go/pkg/mod/github.com/devopsfaith/krakend-lua@v1.1.0/proxy/proxy.go:38 +0x5f
github.com/devopsfaith/krakend-ratelimit/juju/proxy.BackendFactory.func1(0xc0000a4400, 0x2582e20)
        /go/pkg/mod/github.com/devopsfaith/krakend-ratelimit@v1.1.0/juju/proxy/proxy.go:59 +0x55
github.com/devopsfaith/krakend-circuitbreaker/gobreaker/proxy.BackendFactory.func1(0xc0000a4400, 0x8)
        /go/pkg/mod/github.com/devopsfaith/krakend-circuitbreaker@v0.0.0-20190405155253-cf7c0a538981/gobreaker/proxy/proxy.go:38 +0x67
github.com/devopsfaith/krakend/proxy.defaultFactory.newStack(0xc00041ba40, 0x2582e20, 0xc000485580, 0x22b5ee8, 0xc0000a4400, 0x18)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:84 +0x34
github.com/devopsfaith/krakend/proxy.defaultFactory.newSingle(...)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:80
github.com/devopsfaith/krakend/proxy.defaultFactory.New(0xc00041ba40, 0x2582e20, 0xc000485580, 0x22b5ee8, 0xc0003340a0, 0x22b8c48, 0xc000500238, 0x1e65560)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:58 +0x15a
github.com/devopsfaith/krakend/proxy.shadowFactory.New(0x25431c0, 0xc00041ba60, 0xc0003340a0, 0x225b6dd, 0x2b, 0xc0006def88)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/shadow.go:38 +0x363
github.com/devopsfaith/krakend-jsonschema.ProxyFactory.func1(0xc0003340a0, 0x1f53ea0, 0xc000051c40, 0x26de3f00000076)
        /go/pkg/mod/github.com/devopsfaith/krakend-jsonschema@v0.0.0-20190124184701-5705a5015d7a/jsonschema.go:25 +0x3d
github.com/devopsfaith/krakend/proxy.FactoryFunc.New(0xc00041bc20, 0xc0003340a0, 0xc000054800, 0xc0006df020, 0xd0a77f)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:23 +0x30
github.com/devopsfaith/krakend-cel.ProxyFactory.func1(0xc0003340a0, 0xc0006df0b0, 0xda0902, 0xc000130060)
        /go/pkg/mod/github.com/devopsfaith/krakend-cel@v0.0.0-20190502130550-d6872fd4f97e/proxy.go:17 +0x63
github.com/devopsfaith/krakend/proxy.FactoryFunc.New(0xc00031eb70, 0xc0003340a0, 0xc000130060, 0xc00012a180, 0x56)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:23 +0x30
github.com/devopsfaith/krakend-lua/proxy.ProxyFactory.func1(0xc0003340a0, 0xc00012a180, 0x56, 0x80)
        /go/pkg/mod/github.com/devopsfaith/krakend-lua@v1.1.0/proxy/proxy.go:21 +0x69
github.com/devopsfaith/krakend/proxy.FactoryFunc.New(0xc00031eba0, 0xc0003340a0, 0xc000397520, 0x10, 0x10)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:23 +0x30
github.com/devopsfaith/krakend/proxy.FactoryFunc.New(0xc0003d68c0, 0xc0003340a0, 0xcdf55a, 0xc000397520, 0xc000396650)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:23 +0x30
github.com/devopsfaith/krakend/proxy.FactoryFunc.New(0xc0003d68e0, 0xc0003340a0, 0x1f25100, 0xc000397520, 0x0)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/factory.go:23 +0x30
github.com/devopsfaith/krakend/router/gin.ginRouter.registerKrakendEndpoints(0xc000152280, 0x0, 0x0, 0x0, 0xc0003d6a00, 0x25431a0, 0xc0003d68e0, 0x2582e20, 0xc000485580, 0xc0003d6a60, ...)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/router/gin/router.go:105 +0x8b
github.com/devopsfaith/krakend/router/gin.ginRouter.Run(0xc000152280, 0x0, 0x0, 0x0, 0xc0003d6a00, 0x25431a0, 0xc0003d68e0, 0x2582e20, 0xc000485580, 0xc0003d6a60, ...)
        /go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/router/gin/router.go:90 +0x19f
github.com/devopsfaith/krakend-ce.(*ExecutorBuilder).NewCmdExecutor.func1(0xc0004da0b4, 0x7, 0xc000500060, 0x1, 0x1, 0xb2d05e00, 0x45d964b800, 0x3393bf0, 0x0, 0x0, ...)
        /app/executor.go:158 +0x755
github.com/devopsfaith/krakend-cobra.runFunc(0x32452e0, 0xc00055a720, 0x0, 0x2)
        /go/pkg/mod/github.com/devopsfaith/krakend-cobra@v0.0.0-20190403130617-3f056666a23e/run.go:24 +0x189
github.com/spf13/cobra.(*Command).execute(0x32452e0, 0xc00055a680, 0x2, 0x2, 0x32452e0, 0xc00055a680)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:766 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0x3244e20, 0xcd8188, 0x20, 0x20282e0)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:852 +0x2ea
github.com/spf13/cobra.(*Command).Execute(...)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:800
github.com/devopsfaith/krakend-cobra.Execute(0x2543160, 0xc00036ea00, 0xc00055a1a0)
        /go/pkg/mod/github.com/devopsfaith/krakend-cobra@v0.0.0-20190403130617-3f056666a23e/cmd.go:20 +0x62
main.main()
        /app/cmd/krakend-ce/main.go:56 +0x359
taik0 commented 4 years ago

Hi @lbn , you are right. This was fixed in the consumer but not in the producer. Should be fixed in #5