modern-go / reflect2

reflect api without runtime reflect.Value cost
Apache License 2.0
758 stars 73 forks source link

nil pointer panic in wrapType #12

Open fasaxc opened 4 years ago

fasaxc commented 4 years ago

In a CI run of our project, we hit the following panic (using the kubernetes client to list some custom resources):

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

goroutine 165 [running]:
github.com/modern-go/reflect2.(*frozenConfig).wrapType(0xc00036d150, 0xc000666a00, 0xc0001914a0, 0x0, 0x0)
    /go/pkg/mod/github.com/modern-go/reflect2@v1.0.1/reflect2.go:168 +0x6f
github.com/modern-go/reflect2.(*frozenConfig).Type2(0xc00036d150, 0xc000666a00, 0xc0001914a0, 0x1, 0xc000b6e6e0)
    /go/pkg/mod/github.com/modern-go/reflect2@v1.0.1/reflect2.go:161 +0xa1
github.com/modern-go/reflect2.(*UnsafeStructField).Type(0xc000c08000, 0xe0, 0x22900fb)
    /go/pkg/mod/github.com/modern-go/reflect2@v1.0.1/unsafe_field.go:37 +0x45
github.com/json-iterator/go.describeStruct(0xc000c01e30, 0x2855940, 0xc000c01e90, 0x7f0300023d98)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect_extension.go:349 +0xab2
github.com/json-iterator/go.decoderOfStruct(0xc000c01e30, 0x2855940, 0xc000c01e90, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect_struct_decoder.go:14 +0xb6
github.com/json-iterator/go._createDecoderOfType(0xc000c01e30, 0x2855940, 0xc000c01e90, 0xc000b87998, 0xc0003d2f00)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:176 +0x4aa
github.com/json-iterator/go.createDecoderOfType(0xc000c01e30, 0x2855940, 0xc000c01e90, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:142 +0x10b
github.com/json-iterator/go.decoderOfType(0xc000c01e30, 0x2855940, 0xc000c01e90, 0x22900f0, 0x1)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:124 +0x78
github.com/json-iterator/go.describeStruct(0xc00080bc40, 0x2855940, 0xc000bf17d0, 0x7f030000be34)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect_extension.go:380 +0xa4f
github.com/json-iterator/go.decoderOfStruct(0xc00080bc40, 0x2855940, 0xc000bf17d0, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect_struct_decoder.go:14 +0xb6
github.com/json-iterator/go._createDecoderOfType(0xc00080bc40, 0x2855940, 0xc000bf17d0, 0xc0009e7e28, 0x212e0c0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:176 +0x4aa
github.com/json-iterator/go.createDecoderOfType(0xc00080bc40, 0x2855940, 0xc000bf17d0, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:142 +0x10b
github.com/json-iterator/go.decoderOfType(0xc00080bc40, 0x2855940, 0xc000bf17d0, 0x22900f0, 0x1)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:124 +0x78
github.com/json-iterator/go.decoderOfSlice(0xc000bf16e0, 0x28558a0, 0xc000b95740, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect_slice.go:12 +0x105
github.com/json-iterator/go._createDecoderOfType(0xc000bf16e0, 0x28558a0, 0xc000b95740, 0xc0009e7e18, 0xc0003d2f00)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:180 +0x4ff
github.com/json-iterator/go.createDecoderOfType(0xc000bf16e0, 0x28558a0, 0xc000b95740, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:142 +0x10b
github.com/json-iterator/go.decoderOfType(0xc000bf16e0, 0x28558a0, 0xc000b95740, 0x22900f0, 0x1)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:124 +0x78
github.com/json-iterator/go.describeStruct(0xc00080c380, 0x2855940, 0xc000bf0f30, 0x1fbd6)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect_extension.go:380 +0xa4f
github.com/json-iterator/go.decoderOfStruct(0xc00080c380, 0x2855940, 0xc000bf0f30, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect_struct_decoder.go:14 +0xb6
github.com/json-iterator/go._createDecoderOfType(0xc00080c380, 0x2855940, 0xc000bf0f30, 0xc0009e7dc8, 0xc0003d2f00)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:176 +0x4aa
github.com/json-iterator/go.createDecoderOfType(0xc00080c380, 0x2855940, 0xc000bf0f30, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:142 +0x10b
github.com/json-iterator/go.decoderOfType(0xc00080c380, 0x2855940, 0xc000bf0f30, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:124 +0x78
github.com/json-iterator/go.(*frozenConfig).DecoderOf(0xc00049a1e0, 0x2855800, 0xc000bf0e70, 0x2855800, 0xc000bf0e70)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:114 +0x111
github.com/json-iterator/go.(*Iterator).ReadVal(0xc0007cac60, 0x2199a00, 0xc000344070)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/reflect.go:72 +0x1ce
github.com/json-iterator/go.(*frozenConfig).Unmarshal(0xc00049a1e0, 0xc000ba6c00, 0x2d7, 0x600, 0x2199a00, 0xc000344070, 0x0, 0x0)
    /go/pkg/mod/github.com/json-iterator/go@v1.1.8/config.go:348 +0xd2
k8s.io/apimachinery/pkg/runtime/serializer/json.(*Serializer).Decode(0xc0000d4050, 0xc000ba6c00, 0x2d7, 0x600, 0x0, 0x27cb780, 0xc000344070, 0x3d, 0x1, 0x0, ...)
    /go/pkg/mod/k8s.io/apimachinery@v0.17.2/pkg/runtime/serializer/json/json.go:263 +0x600
k8s.io/apimachinery/pkg/runtime.WithoutVersionDecoder.Decode(0x27b2c20, 0xc0000d4050, 0xc000ba6c00, 0x2d7, 0x600, 0x0, 0x27cb780, 0xc000344070, 0xc0008c7600, 0xc0008c7500, ...)
    /go/pkg/mod/k8s.io/apimachinery@v0.17.2/pkg/runtime/helper.go:252 +0x97
k8s.io/client-go/rest.Result.Into(0xc000ba6c00, 0x2d7, 0x600, 0xc000483c20, 0x10, 0x0, 0x0, 0xc8, 0x27b5820, 0xc000bf4360, ...)
    /go/pkg/mod/k8s.io/client-go@v0.17.2/rest/request.go:1182 +0xba
...

We've only seen the panic once so far despite running many CI runs daily.

Reported in json-iter too; not sure where it belongs: https://github.com/json-iterator/go/issues/462