You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/12/01 14:03:03 UTC

[GitHub] [pulsar] flowchartsman opened a new issue #8769: [Go functions]: Panic on discard message

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/pulsar-function-go@v0.0.0-20201130103018-9c28378aea7d/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/pulsar-function-go@v0.0.0-20201130103018-9c28378aea7d/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/pulsar-function-go@v0.0.0-20201130103018-9c28378aea7d/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/pulsar-function-go@v0.0.0-20201130103018-9c28378aea7d/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:
users@infra.apache.org



[GitHub] [pulsar] wolfstudy commented on issue #8769: [Go functions]: Panic on discard message

Posted by GitBox <gi...@apache.org>.
wolfstudy commented on issue #8769:
URL: https://github.com/apache/pulsar/issues/8769#issuecomment-736942898


   @flowchartsman I will fix this issue, thanks to feedback.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [pulsar] flowchartsman commented on issue #8769: [Go functions]: Panic on discard message

Posted by GitBox <gi...@apache.org>.
flowchartsman commented on issue #8769:
URL: https://github.com/apache/pulsar/issues/8769#issuecomment-736733486


   The issue appears to be a mismatch between `inputMessage.Topic()` and the consumers in `gi.consumers`:
   
   If `ackInputMessage` is instrumented like so
   ```go
   // ackInputMessage doesn't produce any result, or the user doesn't want the result.
   func (gi *goInstance) ackInputMessage(inputMessage pulsar.Message) {
   	log.Infof("**********\ntopic is: %s\nconsumers:\n%#v", inputMessage.Topic(), gi.consumers)
   	gi.consumers[inputMessage.Topic()].Ack(inputMessage)
   }
   ```
   In the logs we see:
   
   ```
   2020/12/01 18:17:31.048 log.go:46: [info] **********
   topic is: persistent://public/default/test
   consumers:
   map[string]pulsar.Consumer{"public/default/test":(*pulsar.consumer)(0xc00040cd80)}
   
   ```
   I am unsure whether the failure here is with pulsar-admin or with my use of an abbreviated topic, but in any case a panic is not helpful.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [pulsar] flowchartsman edited a comment on issue #8769: [Go functions]: Panic on discard message

Posted by GitBox <gi...@apache.org>.
flowchartsman edited a comment on issue #8769:
URL: https://github.com/apache/pulsar/issues/8769#issuecomment-736733486


   The issue appears to be a mismatch between `inputMessage.Topic()` and the consumers in `gi.consumers`:
   
   If `ackInputMessage` is instrumented like so
   ```go
   // ackInputMessage doesn't produce any result, or the user doesn't want the result.
   func (gi *goInstance) ackInputMessage(inputMessage pulsar.Message) {
   	log.Infof("**********\ntopic is: %s\nconsumers:\n%#v", inputMessage.Topic(), gi.consumers)
   	gi.consumers[inputMessage.Topic()].Ack(inputMessage)
   }
   ```
   In the logs we see:
   
   ```
   2020/12/01 18:17:31.048 log.go:46: [info] **********
   topic is: persistent://public/default/test
   consumers:
   map[string]pulsar.Consumer{"public/default/test":(*pulsar.consumer)(0xc00040cd80)}
   
   ```
   I am unsure whether the failure here is with pulsar-admin or with my use of an abbreviated topic, but in any case a panic is not helpful, so I would think the right solution would be for pulsar-admin or the API itself to either give me an error or take care of the mapping (with an informative message) so that this state cannot occur.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [pulsar] wolfstudy closed issue #8769: [Go functions]: Panic on discard message

Posted by GitBox <gi...@apache.org>.
wolfstudy closed issue #8769:
URL: https://github.com/apache/pulsar/issues/8769


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [pulsar] wolfstudy commented on issue #8769: [Go functions]: Panic on discard message

Posted by GitBox <gi...@apache.org>.
wolfstudy commented on issue #8769:
URL: https://github.com/apache/pulsar/issues/8769#issuecomment-736917843


   @flowchartsman If our go function does not require a return value, we can use the following method:
   
   ```
   // 	func (context.Context) error
   // 	func (context.Context, input) error
   ```
   
   This panic is caused by not handling the case where the output is nil. When a user uses a signature with an output function, we will assume that the output is a result by default, and we should add the processing of the nil value here, thanks @flowchartsman feedback.


----------------------------------------------------------------
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:
users@infra.apache.org