weixin_39686048
weixin_39686048
2020-11-23 05:04

Nil pointer exception on v2.(*client).reportError()

Describe the bug With a knative source example [1] and the following versions github.com/cloudevents/sdk-go/v2 v2.2.0 and knative.dev/eventing v0.18.1-0.20201022155237-554e4b306de4 I am getting nil pointer exceptions in the source adapter after invoking Send() on the client:


panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x17be546]
goroutine 1 [running]:
knative.dev/eventing/pkg/adapter/v2.(*client).reportError(0xc00042e0c0, 0xc0003d2380, 0x7f4b653a89f8, 0xc00042fb90, 0xc00042fb00, 0x30b)
        knative.dev/eventing.18.1-0.20201022155237-554e4b306de4/pkg/adapter/v2/cloudevents.go:190 +0xa6
knative.dev/eventing/pkg/adapter/v2.(*client).reportCount(0xc00042e0c0, 0x2458e20, 0xc0002d5380, 0x247d320, 0xc0005f8380, 0xc0001a2380, 0x30b, 0x30b, 0x0, 0xc00042f9b0, ...)
        knative.dev/eventing.18.1-0.20201022155237-554e4b306de4/pkg/adapter/v2/cloudevents.go:171 +0x67f
knative.dev/eventing/pkg/adapter/v2.(*client).Send(0xc00042e0c0, 0x2458e20, 0xc0002d5380, 0x247d320, 0xc0005f8380, 0xc0001a2380, 0x30b, 0x30b, 0x0, 0xc00042f9b0, ...)
        knative.dev/eventing.18.1-0.20201022155237-554e4b306de4/pkg/adapter/v2/cloudevents.go:120 +0x119
github.com/vmware-tanzu/sources-for-knative/pkg/vsphere.(*vAdapter).sendEvents.func1(0xc000117720, 0x6, 0xc000117740, 0x8, 0xc0000b5800, 0x1, 0x10, 0xc0009bdec0, 0x0)
        github.com/vmware-tanzu/sources-for-knative/pkg/vsphere/adapter.go:107 +0x42e
github.com/vmware/govmomi/event.(*eventProcessor).process(0xc000a0f440, 0xc000056da0, 0x15, 0xc000020540, 0x51, 0xc00042e8a0, 0x1, 0x1, 0x0, 0x0)
        github.com/vmware/govmomi.22.2-0.20200505195818-967bc5808c63/event/processor.go:148 +0x203
github.com/vmware/govmomi/event.(*eventProcessor).run.func1(0xc00042e8a0, 0x1, 0x1, 0x0)
        github.com/vmware/govmomi.22.2-0.20200505195818-967bc5808c63/event/processor.go:102 +0x88
github.com/vmware/govmomi/property.Wait.func1(0xc00092a720, 0x1, 0x1, 0xc00015c000)
        github.com/vmware/govmomi.22.2-0.20200505195818-967bc5808c63/property/wait.go:64 +0xd8
github.com/vmware/govmomi/property.WaitForUpdates(0x2458e20, 0xc0002d5380, 0xc000511038, 0xc000a0eeb0, 0xc000a0ee30, 0x0, 0x0)
        github.com/vmware/govmomi.22.2-0.20200505195818-967bc5808c63/property/wait.go:146 +0x37c
github.com/vmware/govmomi/property.Wait(0x2458e20, 0xc0002d5380, 0xc000511038, 0xc000056da0, 0x15, 0xc000020540, 0x51, 0xc000801b40, 0x1, 0x1, ...)
        github.com/vmware/govmomi.22.2-0.20200505195818-967bc5808c63/property/wait.go:62 +0x258
github.com/vmware/govmomi/event.(*eventProcessor).run(0xc000511440, 0x2458e20, 0xc0002d5380, 0xc000117701, 0x0, 0x0)
        github.com/vmware/govmomi.22.2-0.20200505195818-967bc5808c63/event/processor.go:101 +0xba8
github.com/vmware/govmomi/event.Manager.Events(0x0, 0x0, 0xc00015c000, 0xc0005b40c0, 0xc, 0xc0005b40f0, 0xc, 0xc000811980, 0xc0005b4ff8, 0xa, ...)
        github.com/vmware/govmomi.22.2-0.20200505195818-967bc5808c63/event/manager.go:188 +0x225
github.com/vmware-tanzu/sources-for-knative/pkg/vsphere.(*vAdapter).Start(0xc000139db0, 0x2458e20, 0xc0002d5380, 0x0, 0x0)
        github.com/vmware-tanzu/sources-for-knative/pkg/vsphere/adapter.go:82 +0x30a
knative.dev/eventing/pkg/adapter/v2.MainWithInformers(0x2458e20, 0xc0002d4ff0, 0x2109941, 0xd, 0x246fe60, 0xc0001129c0, 0x21eb4e0)
        knative.dev/eventing.18.1-0.20201022155237-554e4b306de4/pkg/adapter/v2/main.go:198 +0x100a
knative.dev/eventing/pkg/adapter/v2.MainWithEnv(0x2458e20, 0xc0002d4ff0, 0x2109941, 0xd, 0x246fe60, 0xc0001129c0, 0x21eb4e0)
        knative.dev/eventing.18.1-0.20201022155237-554e4b306de4/pkg/adapter/v2/main.go:105 +0x230
knative.dev/eventing/pkg/adapter/v2.MainWithContext(0x2458e20, 0xc0002d4ff0, 0x2109941, 0xd, 0x21eb4e8, 0x21eb4e0)
        knative.dev/eventing.18.1-0.20201022155237-554e4b306de4/pkg/adapter/v2/main.go:80 +0x75
main.main()
        github.com/vmware-tanzu/sources-for-knative/cmd/sources-for-knative-adapter/main.go:27 +0xfb

The code path:

go
    err := errors.Unwrap(result)
    if uerr, ok := err.(*url.Error); ok {
        reportArgs.Timeout = uerr.Timeout()
    }
    reportArgs.Error = err.Error()
    if rErr := c.reporter.ReportEventCount(reportArgs, 0); rErr != nil {
        // metrics is not important enough to return an error if it is setup wrong.
        // So combine reporter error with ce error if not nil.
        if result != nil {
            result = fmt.Errorf("%w\nmetrics reporter error: %s", result, rErr)
        }
    }

[1] https://github.com/vmware-tanzu/sources-for-knative

Expected behavior Error message or successful processing w/out panic.

To Reproduce Deploy this example: https://github.com/vmware-tanzu/sources-for-knative

Knative release version Relevant go.mod in the source:

go
module github.com/vmware-tanzu/sources-for-knative

go 1.14

require (
    github.com/braintree/manners v0.0.0-20160418043613-82a8879fc5fd // indirect
    github.com/cloudevents/sdk-go/v2 v2.2.0
    github.com/codegangsta/cli v0.0.0-00010101000000-000000000000 // indirect
    github.com/davecgh/go-spew v1.1.1
    github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
    github.com/fatih/structs v1.1.0 // indirect
    github.com/gobuffalo/envy v1.9.0 // indirect
    github.com/google/go-cmp v0.5.2
    github.com/kelseyhightower/envconfig v1.4.0
    github.com/spf13/cobra v1.0.0
    github.com/vmware/govmomi v0.22.2-0.20200505195818-967bc5808c63
    github.com/yudai/gotty v1.0.1
    github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552 // indirect
    github.com/yudai/umutex v0.0.0-20150817080136-18216d265c6b // indirect
    go.uber.org/zap v1.15.0
    golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
    gotest.tools v2.2.0+incompatible
    k8s.io/api v0.18.8
    k8s.io/apimachinery v0.18.8
    k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
    k8s.io/code-generator v0.18.8
    k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29
    knative.dev/eventing v0.18.1-0.20201022155237-554e4b306de4
    knative.dev/pkg v0.0.0-20201023012137-324e49bc7fe1
)

replace (
    github.com/codegangsta/cli => github.com/urfave/cli v1.19.1
    github.com/kr/pretty => github.com/dougm/pretty v0.0.0-20171025230240-2ee9d7453c02

    k8s.io/api => k8s.io/api v0.18.8
    k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.8
    k8s.io/apimachinery => k8s.io/apimachinery v0.18.8
    k8s.io/apiserver => k8s.io/apiserver v0.18.8
    k8s.io/client-go => k8s.io/client-go v0.18.8
    k8s.io/code-generator => k8s.io/code-generator v0.18.8
    k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6
)

Additional context n/a

该提问来源于开源项目:knative/eventing

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39781143 weixin_39781143 5月前

    Unwrapping returned nil

    err := errors.Unwrap(result)

    causing the panic at reportArgs.Error = err.Error()

    https://play.golang.org/p/WAnHGnn5Llp

    点赞 评论 复制链接分享
  • weixin_39686048 weixin_39686048 5月前

    Likely caused due to result in this case not implementing Unwrap, i.e. not constructed via %w thus becoming nil.

    点赞 评论 复制链接分享
  • weixin_39843215 weixin_39843215 5月前

    https://github.com/knative/eventing/pull/3085/files#diff-edcf3408191e5c1035d184fd9b6cabb49928ab76d56a1b5b1d162502fc109218R109

    /cc

    点赞 评论 复制链接分享
  • weixin_39761573 weixin_39761573 5月前

    Yeah looks like Result is not implementing Unwrap: https://github.com/cloudevents/sdk-go/blob/master/v2/protocol/http/result.go

    点赞 评论 复制链接分享
  • weixin_39686048 weixin_39686048 5月前

    It actually does IIUC, because it depends on how you construct result (uses fmt.Error). If messageFmt is using %w then it will is my understanding.

    // update you're right, I was referring to this one: https://github.com/cloudevents/sdk-go/blob/master/v2/protocol/result.go

    // works if used with %w

    go
    func NewResult(messageFmt string, args ...interface{}) Result {
        return fmt.Errorf(messageFmt, args...)
    }
    
    点赞 评论 复制链接分享

相关推荐