connect icon indicating copy to clipboard operation
connect copied to clipboard

redis cache missing args_mapping causes panic

Open cawalch opened this issue 2 years ago • 1 comments

Problem

Missing args_mapping from redis processor causes panic during runtime.

Example

input:
   stdin: {}

pipeline:
  processors:
    - redis:
         url: redis://localhost:6379
         command: foo

output:
   stdout: {}

Result

❯ ./target/bin/benthos -c config.yaml
INFO Running main config from specified file       @service=benthos path=config.yaml
INFO Launching a benthos instance, use CTRL+C to close  @service=benthos
INFO Listening for HTTP requests at: http://0.0.0.0:4195  @service=benthos
{"foo":"foobar"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1a556e7]

goroutine 40 [running]:
github.com/benthosdev/benthos/v4/public/service.MessageBatch.BloblangQuery({0xc001188cd0, 0x1, 0xc001586ff0?}, 0x110d4c6?, 0x11f2a10?)
	/Users/___/benthos/public/service/message.go:276 +0x27
github.com/benthosdev/benthos/v4/internal/impl/redis.(*redisProc).execRaw(0xc0015865a0, {0x454bd08, 0xc000f1e000}, 0x8?, {0xc001188cd0, 0x1, 0x1}, 0xc001188ce8)
	/Users/___/benthos/internal/impl/redis/processor.go:308 +0x78
github.com/benthosdev/benthos/v4/internal/impl/redis.(*redisProc).ProcessBatch(0xc0015865a0, {0x454bd08, 0xc000f1e000}, {0xc001188cd0?, 0x1, 0x1})
	/Users/___/benthos/internal/impl/redis/processor.go:362 +0x4d0
github.com/benthosdev/benthos/v4/public/service.(*airGapBatchProcessor).ProcessBatch(0xc000d3a1e0, {0x454bd08, 0xc000f1e000}, {0x5?, 0xc000014078?, 0x1?}, {0xc000014078, 0x1, 0x1})
	/Users/___/benthos/public/service/processor.go:109 +0xee
github.com/benthosdev/benthos/v4/internal/component/processor.(*v2BatchedToV1Processor).ProcessBatch(0xc0001a1050, {0x454bd08, 0xc000f1e000}, {0xc000014078?, 0x1, 0x1})
	/Users/___/benthos/internal/component/processor/processor_v2.go:146 +0x157
github.com/benthosdev/benthos/v4/internal/component/processor.ExecuteAll({0x454bd08, 0xc000f1e000}, {0xc000bc7140, 0x1, 0x0?}, {0xc000c84ec0?, 0x1, 0x0?})
	/Users/___/benthos/internal/component/processor/execute.go:22 +0x1b6
github.com/benthosdev/benthos/v4/internal/pipeline.(*Processor).loop(0xc000b2cf00)
	/Users/___/benthos/internal/pipeline/processor.go:69 +0x285
created by github.com/benthosdev/benthos/v4/internal/pipeline.(*Processor).Consume
	/Users/___/benthos/internal/pipeline/processor.go:139 +0x79

Version

v4.4.1-73-gf8b1fd9d

Possible Fix

Remove Default value

diff --git a/internal/impl/redis/processor.go b/internal/impl/redis/processor.go
index 4443e8f4..bc353280 100644
--- a/internal/impl/redis/processor.go
+++ b/internal/impl/redis/processor.go
@@ -36,8 +36,7 @@ performed for each message and the message contents are replaced with the result
                        Description("A [Bloblang mapping](/docs/guides/bloblang/about) which should evaluate to an array of values matching in size to the number of arguments required for the specified Redis comm>
                        Version("4.3.0").
                        Example("root = [ this.key ]").
-                       Example(`root = [ meta("kafka_key"), this.count ]`).
-                       Default(``)).
+                       Example(`root = [ meta("kafka_key"), this.count ]`)).
                Field(service.NewStringAnnotatedEnumField("operator", map[string]string{
                        "keys":   `Returns an array of strings containing all the keys that match the pattern specified by the ` + "`key` field" + `.`,
                        "scard":  `Returns the cardinality of a set, or ` + "`0`" + ` if the key does not exist.`,

cawalch avatar Aug 09 '22 21:08 cawalch

Nice find! I sent a patch for this in #1372.

mihaitodor avatar Aug 09 '22 22:08 mihaitodor