Skip to content

panic: nil pointer dereference in events recorder during reconcile #25

@ifdotpy

Description

@ifdotpy

Bug

When init-agent reconciles a LogicalCluster in the per-WorkspaceType init controller, it can panic with:

```
panic: runtime error: invalid memory address or nil pointer dereference
```

Stack trace points to `multicluster-provider/pkg/events/recorder.getBroadcaster`:

```
github.com/kcp-dev/multicluster-provider/pkg/events/recorder.(*Provider).getBroadcaster(0x0, 0xc00072a488, ...)
forked_recorder.go:105
github.com/kcp-dev/multicluster-provider/pkg/events/recorder.(*lazyRecorder).ensureRecording.func1()
forked_recorder.go:179
sync.(*Once).doSlow ...
github.com/kcp-dev/multicluster-provider/pkg/events/recorder.(*lazyRecorder).Eventf(0xc0005320a0, ...)
forked_recorder.go:196
github.com/kcp-dev/init-agent/internal/controller/initcontroller.(*Reconciler).Reconcile
reconciler.go:78
```

The receiver `*Provider` is nil at the call site (`0x0`). The lazy recorder calls `ensureRecording` and dereferences a nil broadcaster provider.

The panic is recovered by controller-runtime so reconciliation eventually succeeds on retry, but logs are noisy and the reconcile gets requeued unnecessarily.

Environment

Steps to reproduce

  1. Configure init-agent --config-workspace as an APIExport virtual workspace path.
  2. Create an InitTarget pointing at `workspaceTypeRef: {path: root, name: account}`.
  3. Create a workspace whose effective WorkspaceType chain includes `root:account` with `spec.initializer: true`.
  4. Watch init-agent logs as it processes the cluster.

Suggested fix

Either:

  • Initialize `*Provider` properly before any reconcile (init-agent setup path needs to call something), or
  • Guard the receiver in `getBroadcaster` so it returns a no-op recorder when no broadcaster is configured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions