[Go, Functions] Panic while goInstance.ackInputMessage
See original GitHub issueDescribe the bug
I am testing a simple Go function with Pulsar in standalone in docker. When setting --auto-ack true
i get a panic from pulsar-function-go/pf/instance.go
in ackInputMessage
.
I build it in my system, docker cp
it in the Pulsar container and run it using:
bin/pulsar-admin functions localrun --auto-ack true --go /pulsar/inputFunc --inputs persistent://zerogap/test-nam/in-msgs --output non-persistent://zerogap/test-nam/filtered-msgs --tenant zerogap --namespace test-nam --name test-input-go-function --retain-ordering --retain-key-ordering --user-config '{"custom-data":"12345"}'
The simple function’s code is:
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/apache/pulsar/pulsar-function-go/pf"
)
func contextFunc(ctx context.Context) string {
fc, ok := pf.FromContext(ctx)
if !ok {
fmt.Printf("Function context is not defined")
}
wotd := fc.GetUserConfValue("custom-data")
if wotd == nil {
fmt.Printf("custom-data is empty. set it with --user-config")
return ""
} else {
fmt.Printf("custom-data is %s", wotd.(string))
return wotd.(string)
}
}
func FilterData(ctx context.Context, input []byte) ([]byte, error) {
wotd := contextFunc(ctx)
fmt.Printf("Input message in topic is: %s\n", input)
fmt.Printf("Filtering radar for custom-data: %s\n", wotd)
var dat map[string]interface{}
if err := json.Unmarshal(input, &dat); err != nil {
panic(err)
}
fmt.Println(dat)
return input, nil
}
func main() {
pf.Start(FilterData)
}
To Reproduce Steps to reproduce the behavior:
- Start Pulsar in standalone mode
- Create the topics the function will be using as input/output
- Add simple Go function
- Start the function with the command arguments as above(especially having
--auto-ack
set totrue
) - See error below
Expected behavior Expect to have message acknowledgement without panic exit.
Screenshots Panic log:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xaece73]
goroutine 74 [running]:
github.com/apache/pulsar/pulsar-function-go/pf.(*goInstance).ackInputMessage(0xc000214a00, {0xe75e60, 0xc0001fe2d0})
/home/zerogap/go/pkg/mod/github.com/apache/pulsar/pulsar-function-go@v0.0.0-20220410070944-960580764bbc/pf/instance.go:396 +0xb3
github.com/apache/pulsar/pulsar-function-go/pf.(*goInstance).processResult.func1({0xd11780?, 0x3f52aa8fe9a01fce?}, 0x1?, {0x0?, 0x0?})
/home/zerogap/go/pkg/mod/github.com/apache/pulsar/pulsar-function-go@v0.0.0-20220410070944-960580764bbc/pf/instance.go:378 +0x112
github.com/apache/pulsar-client-go/pulsar.(*partitionProducer).ReceivedSendReceipt(0xc0000ac000, 0xc000230540)
/home/zerogap/go/pkg/mod/github.com/apache/pulsar-client-go@v0.8.1/pulsar/producer_partition.go:830 +0x7f0
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).handleSendReceipt(0xc00017dce0, 0xc000230540)
/home/zerogap/go/pkg/mod/github.com/apache/pulsar-client-go@v0.8.1/pulsar/internal/connection.go:673 +0xe8
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).internalReceivedCommand(0xc00017dce0, 0xc0006285a0, {0x0?, 0x0})
/home/zerogap/go/pkg/mod/github.com/apache/pulsar-client-go@v0.8.1/pulsar/internal/connection.go:558 +0x14a
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).run(0xc00017dce0)
/home/zerogap/go/pkg/mod/github.com/apache/pulsar-client-go@v0.8.1/pulsar/internal/connection.go:415 +0x3a5
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).start.func1()
/home/zerogap/go/pkg/mod/github.com/apache/pulsar-client-go@v0.8.1/pulsar/internal/connection.go:227 +0x65
created by github.com/apache/pulsar-client-go/pulsar/internal.(*connection).start
/home/zerogap/go/pkg/mod/github.com/apache/pulsar-client-go@v0.8.1/pulsar/internal/connection.go:223 +0x70
Desktop (please complete the following information):
- OS: Host: Ubuntu 20, Guest: whatever Pulsar container has(
apachepulsar/pulsar:latest
)
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Go function panic due to non-canonical topic #6790 - GitHub
Describe the bug When creating a go function with an input topic name that is non-canonical (e.g. public/default/input), the function panics ...
Read more >[Go, Functions] Panic while goInstance.ackInputMessage
[GitHub] [pulsar] github-actions[bot] commented on issue #15100: [Go, Functions] Panic while goInstance.ackInputMessage.
Read more >Handling Panics in Go - DigitalOcean
Panics are unforeseeable errors that will spontaneously terminate and exit a running Go program. Common mistakes are often responsible for ...
Read more >Defer, Panic, and Recover - The Go Programming Language
Panic is a built-in function that stops the ordinary flow of control and begins panicking. When the function F calls panic, execution of...
Read more >Panic in Golang - GeeksforGeeks
This function terminates the flow of control and starts panicking. Syntax: func panic(v interface{}). It can receive any type of argument. When ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have tested it and it’s working for me.
pulsar version: 2.9.2
produce message:
function log:
The issue had no activity for 30 days, mark with Stale label.