Skip to content

Conversation

mjudeikis
Copy link
Contributor

@mjudeikis mjudeikis commented Sep 3, 2025

Description of your changes

The problem is that when r.external.Connect(externalCtx, managed) fails at line 1086, the code returns early at line 1102, but the defer function at line 1105 still executes. However, since the Connect call failed, the external variable was ever properly assigned a valid value, so it's nil.

When the defer function tries to call external.Disconnect(ctx) at line 1111, it's trying to call a method on a nil pointer, causing the panic.

k8s.io/apimachinery/pkg/util/runtime.logPanic({0x1395160, 0x259ae40})
        k8s.io/[email protected]/pkg/util/runtime/runtime.go:75 +0x7c
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:103 +0xa4
panic({0x1395160?, 0x259ae40?})
        runtime/panic.go:770 +0x124
github.com/crossplane/crossplane-runtime/pkg/reconciler/managed.ExternalClientFns.Disconnect(...)
        github.com/crossplane/[email protected]/pkg/reconciler/managed/reconciler.go:387
github.com/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile.func2()
        github.com/crossplane/[email protected]/pkg/reconciler/managed/reconciler.go:967 +0x1e8
github.com/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile(0x400033f560, {0x18964c8, 0x40007c5c20}, {{{0x0, 0x0}, {0x40006fa940, 0x3d}}})
        github.com/crossplane/[email protected]/pkg/reconciler/managed/reconciler.go:1253 +0x758c
github.com/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile(0x400016a690, {0x18964c8, 0x40007c5c20}, {{{0x0?, 0x400015dca8?}, {0x40006fa940?, 0x400015dd08?}}})
        github.com/crossplane/[email protected]/pkg/ratelimiter/reconciler.go:54 +0x124
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x189ab10?, {0x18964c8?, 0x40007c5c20?}, {{{0x0?, 0xb?}, {0x40006fa940?, 0x0?}}})
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:114 +0x8c
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0x400014e4d0, {0x1896500, 0x4000149d10}, {0x141fb40, 0x40000b2140})
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:311 +0x2dc
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0x400014e4d0, {0x1896500, 0x4000149d10})
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:261 +0x16c
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:222 +0x74
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2 in goroutine 99
        sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:218 +0x3bc

Fixes #

I have:

Need help with this checklist? See the cheat sheet.

@mjudeikis mjudeikis requested a review from a team as a code owner September 3, 2025 08:01
@mjudeikis mjudeikis requested a review from negz September 3, 2025 08:01
Signed-off-by: Mangirdas Judeikis <[email protected]>
@mjudeikis mjudeikis changed the title fix npe Fix npe in reconciler Sep 3, 2025
Copy link
Member

@jbw976 jbw976 left a comment

Choose a reason for hiding this comment

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

This looks reasonable, thank you for taking the time to make this change @mjudeikis and to explain how it is caused too! 🙇‍♂️

@jbw976
Copy link
Member

jbw976 commented Sep 4, 2025

Approved CI workflows to run just now...

@jbw976 jbw976 merged commit 5ea4f6f into crossplane:main Sep 10, 2025
10 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