Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for nil before calling IsKnown() #425

Merged
merged 2 commits into from
Aug 2, 2024
Merged

Conversation

tchinmai7
Copy link
Contributor

Description of your changes

Check for a non-nil Value1 before proceeding to call IsKnown() and IsNull() on it. We noticed a stack trace when running provider-linode v0.22.0

E0725 14:53:33.880315   79095 runtime.go:79] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)
goroutine 3017 [running]:
k8s.io/apimachinery/pkg/util/runtime.logPanic({0x1039ea0c0, 0x10515e330})
        k8s.io/[email protected]/pkg/util/runtime/runtime.go:75 +0xdc
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:108 +0x118
panic({0x1039ea0c0?, 0x10515e330?})
        runtime/panic.go:770 +0xf0
github.com/crossplane/upjet/pkg/controller.(*terraformPluginFrameworkExternalClient).getDiffPlanResponse(0x14002aa6240, {0x103e14108, 0x14002a1c1c0}, {{0x103e1f810, 0x14002cf0270}, {0x1039bce20, 0x14002ce1b60}})
        github.com/crossplane/[email protected]/pkg/controller/external_tfpluginfw.go:282 +0x710
github.com/crossplane/upjet/pkg/controller.(*terraformPluginFrameworkExternalClient).Observe(0x14002aa6240, {0x103e14108, 0x14002a1c1c0}, {0x103e34da8, 0x14002a2a008})
        github.com/crossplane/[email protected]/pkg/controller/external_tfpluginfw.go:330 +0x658
github.com/crossplane/upjet/pkg/controller.(*terraformPluginFrameworkAsyncExternalClient).Observe(0x14000891880, {0x103e14108, 0x14002a1c1c0}, {0x103e34da8, 0x14002a2a008})
        github.com/crossplane/[email protected]/pkg/controller/external_async_tfpluginfw.go:122 +0x254
github.com/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile(0x140001c7a00, {0x103e14108, 0x14002a1c150}, {{{0x0, 0x0}, {0x14000fafe0c, 0x3}}})
        github.com/crossplane/[email protected]/pkg/reconciler/managed/reconciler.go:914 +0x3554
github.com/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile(0x1400069ca00, {0x103e14060, 0x14002a0a210}, {{{0x0, 0x0}, {0x14000fafe0c, 0x3}}})
        github.com/crossplane/[email protected]/pkg/ratelimiter/reconciler.go:54 +0x178
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x140004d5040, {0x103e14060, 0x14002a0a210}, {{{0x0, 0x0}, {0x14000fafe0c, 0x3}}})
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:119 +0x168
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0x140004d5040, {0x103e14060, 0x14002a0a210}, {0x103b24880, 0x14000890dc0})
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:316 +0x3c0
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0x140004d5040, {0x103e14098, 0x140005e7bd0})
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266 +0x340
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227 +0xd0
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2 in goroutine 158
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:223 +0x7c4
2024-07-25T14:53:33-07:00       ERROR   Reconciler error        {"controller": "managed/objectstorage.linode.upbound.io/v1alpha1, kind=key", "namespace": "", "name": "foo", "reconcileID": "f491b43c-3e72-4dfe-b646-44c8395c7a72", "error": "panic: runtime error: invalid memory address or nil pointer dereference [recovered]"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:329
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227

attaching a debugger and looking at the rawDiff slice showed a bunch of resources with a nil Value1. Adding a check before calling functions on that value fixed the problem.

Fixes #

I have:

  • Read and followed Upjet's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Signed-off-by: Tarun Chinmai Sekar <[email protected]>
Signed-off-by: Tarun Chinmai Sekar <[email protected]>
Copy link
Member

@sergenyalcin sergenyalcin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tchinmai7 LGTM!

@sergenyalcin sergenyalcin merged commit 1644827 into crossplane:main Aug 2, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants