Skip to content

Fix nil pointer panic in timedOut when timeoutTimestamp is unset - #151

Open
travisim wants to merge 1 commit into
atlassian-labs:masterfrom
travisim:fix/timedout-nil-timestamp
Open

travisim wants to merge 1 commit into
atlassian-labs:masterfrom
travisim:fix/timedout-nil-timestamp

Conversation

@travisim

Copy link
Copy Markdown

Root cause

CycleNodeStatusStatus.TimeoutTimestamp is a *metav1.Time and is optional, but
CycleNodeStatusTransitioner.timedOut() dereferenced it unconditionally:

return time.Now().After(t.cycleNodeStatus.Status.TimeoutTimestamp.Time)

The timestamp is only set in transitionUndefined when the CycleNodeStatus is
first created. A CycleNodeStatus that reaches DrainingPods with
.status.timeoutTimestamp unset therefore panics inside the controller.
controller-runtime recovers and requeues, so the panic repeats and the node
cycle never progresses.

Fix

Return false (not timed out yet) when the timestamp is unset. Behaviour for
objects that went through the Pending phase is unchanged.

Test

TestTimedOut in util_test.go covers nil, past and future timestamps.

Before the fix, the nil case panics at exactly the line in the reported stack
trace:

--- FAIL: TestTimedOut (0.00s)
    --- FAIL: TestTimedOut/no_timeout_timestamp (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1066b7ffc]
...
github.com/atlassian-labs/cyclops/pkg/controller/cyclenodestatus/transitioner.(*CycleNodeStatusTransitioner).timedOut(0x...)
	.../pkg/controller/cyclenodestatus/transitioner/util.go:42
github.com/atlassian-labs/cyclops/pkg/controller/cyclenodestatus/transitioner.TestTimedOut.func1(...)
	.../pkg/controller/cyclenodestatus/transitioner/util_test.go:49
FAIL	github.com/atlassian-labs/cyclops/pkg/controller/cyclenodestatus/transitioner	0.774s

After the fix:

=== RUN   TestTimedOut
=== RUN   TestTimedOut/no_timeout_timestamp
=== RUN   TestTimedOut/timeout_in_the_past
=== RUN   TestTimedOut/timeout_in_the_future
--- PASS: TestTimedOut (0.00s)
PASS
ok  	github.com/atlassian-labs/cyclops/pkg/controller/cyclenodestatus/transitioner	0.640s

Full repository test suite after the change:

ok  	github.com/atlassian-labs/cyclops/pkg/apis/atlassian/v1	0.307s
ok  	github.com/atlassian-labs/cyclops/pkg/cloudprovider/aws	0.349s
ok  	github.com/atlassian-labs/cyclops/pkg/controller	0.610s
ok  	github.com/atlassian-labs/cyclops/pkg/controller/cyclenoderequest	0.539s
ok  	github.com/atlassian-labs/cyclops/pkg/controller/cyclenoderequest/transitioner	0.661s
ok  	github.com/atlassian-labs/cyclops/pkg/controller/cyclenodestatus/transitioner	0.422s
ok  	github.com/atlassian-labs/cyclops/pkg/controller/node	0.568s
ok  	github.com/atlassian-labs/cyclops/pkg/generation	1.002s
ok  	github.com/atlassian-labs/cyclops/pkg/k8s	1.042s
ok  	github.com/atlassian-labs/cyclops/pkg/manager	0.512s
ok  	github.com/atlassian-labs/cyclops/pkg/metrics	0.933s
ok  	github.com/atlassian-labs/cyclops/pkg/notifications/slack	0.301s
ok  	github.com/atlassian-labs/cyclops/pkg/observer	0.990s
ok  	github.com/atlassian-labs/cyclops/pkg/observer/k8s	0.992s

go build ./... and go vet ./pkg/controller/cyclenodestatus/transitioner/ are clean.

Fixes #146

CycleNodeStatusStatus.TimeoutTimestamp is optional, but timedOut
dereferenced it unconditionally. A CycleNodeStatus that reached the
DrainingPods phase without a timeout timestamp panicked the controller,
and because controller-runtime recovers and requeues, the node cycle
never progressed.

Treat an unset timestamp as not timed out. The timestamp is only set when
the CycleNodeStatus is first created, so this preserves the existing
behaviour for every object that went through the Pending phase.

Fixes atlassian-labs#146

Signed-off-by: Travis Sim <travis@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 22:50
@atlassian-cla-bot

atlassian-cla-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Thank you for your submission! Like many open source projects, we ask that you sign our CLA (Contributor License Agreement) before we can accept your contribution.
If your email is listed below, please ensure that you sign the CLA with the same email address.

The following users still need to sign our CLA:
❌travisim

Already signed the CLA? To re-check, try refreshing the page.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@travisim
travisim force-pushed the fix/timedout-nil-timestamp branch from 9b314b3 to c8278eb Compare November 30, 2026 13:16
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.

[BUG] CycleNodeStatus with nil timeoutTimestamp panics in timedOut() and wedges DrainingPods

2 participants