flowchartsman opened a new issue #8769:
URL: https://github.com/apache/pulsar/issues/8769
**Describe the bug**
Go functions with the signature `func contextFunc(ctx context.Context, in
[]byte) ([]byte, error)` crash on attempting to discard the message by
returning nil.
**To Reproduce**
Create a pulsar function with the following code:
```go
package main
import (
"context"
log "github.com/apache/pulsar/pulsar-function-go/logutil"
"github.com/apache/pulsar/pulsar-function-go/pf"
)
func contextFunc(ctx context.Context, in []byte) ([]byte, error) {
log.Info("attempting to discard input")
return nil, nil
}
func main() {
pf.Start(contextFunc)
}
```
Deploy: `pulsar-admin functions create --name test --namespace default --go
<path to function binary> --inputs test --output test.out`
```
2020/12/01 13:49:50.490 main.go:11: [info] attempting to discard input
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xb06313]
goroutine 1 [running]:
github.com/apache/pulsar/pulsar-function-go/pf.(*goInstance).ackInputMessage(0xc0002a72c0,
0xd85c20, 0xc000416000)
/<home
dir>/go/pkg/mod/github.com/apache/pulsar/[email protected]/pf/instance.go:361
+0x73
github.com/apache/pulsar/pulsar-function-go/pf.(*goInstance).processResult(0xc0002a72c0,
0xd85c20, 0xc000416000, 0x0, 0x0, 0x0)
/<home
dir>/go/pkg/mod/github.com/apache/pulsar/[email protected]/pf/instance.go:352
+0x85
github.com/apache/pulsar/pulsar-function-go/pf.(*goInstance).startFunction(0xc0002a72c0,
0xd6e8a0, 0xc00003c740, 0x0, 0x0)
/<home
dir>/go/pkg/mod/github.com/apache/pulsar/[email protected]/pf/instance.go:176
+0x58e
github.com/apache/pulsar/pulsar-function-go/pf.Start(0xb9a360, 0xcb9340)
/<home
dir>/go/pkg/mod/github.com/apache/pulsar/[email protected]/pf/function.go:171
+0x6b
main.main()
/<home dir>/go/src/scratch/pulsartest/cmd/brokenfunc/main.go:16 +0x39
```
**Expected behavior**
Message discarded. Function does not crash
**Additional context**
The code crashes in the following function:
```go
// ackInputMessage doesn't produce any result, or the user doesn't want the
result.
func (gi *goInstance) ackInputMessage(inputMessage pulsar.Message) {
gi.consumers[inputMessage.Topic()].Ack(inputMessage)
}
```
which is called by
[*goInstance.processResult](https://github.com/apache/pulsar/blob/7f62bbcbd687d67d5b3fd9b1bab2101e64c42c59/pulsar-function-go/pf/instance.go#L326)
in the case of a nil return in this example.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]