tektoncd / results

Long term storage of execution results.
Apache License 2.0
77 stars 73 forks source link

fix: prevent panic when a record Summary is not a valid object #702

Closed ramessesii2 closed 7 months ago

ramessesii2 commented 8 months ago

Changes

There were occurrences of runtime panic due to a nil pointer dereference prior to the code modification suggested in this PR. It specifically occurs because the code does not currently handle cases where curr.Summary could be nil, leading to a crash if it tries to access the Annotations field on a nil object. Here's a panic instance:

{"severity":"debug","timestamp":"2024-02-02T11:35:16.921+0530","logger":"watcher","caller":"results/results.go:305","message":"Record doesn't exist yet - creating","commit":"e1f8cbc-dirty","knative.dev/traceid":"0135a529-2d00-46b0-bf29-4527b54cddb6","knative.dev/key":"test/hello-dcz2q-hello","results.tekton.dev/kind":"TaskRun","results.tekton.dev/record":"test/results/502876c1-6aa0-4371-85ab-cfa2ae89696b/records/8340355b-ec4d-4aab-88f6-f79f9b0a008b"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4129095]

goroutine 77 [running]:
github.com/tektoncd/results/pkg/watcher/results.(*Client).ensureResult(0xc00052e900, {0x4cb6780, 0xc000d04f90}, {0x4cd7af0, 0xc0004aec80}, {0x0, 0x0, 0x0})
    /home/ramesses/Work/redhat/results/pkg/watcher/results/results.go:150 +0xff5
github.com/tektoncd/results/pkg/watcher/results.(*Client).Put(0xc00052e900, {0x4cb6780, 0xc000d04f90}, {0x4cd7af0, 0xc0004aec80}, {0x0, 0x0, 0x0})
    /home/ramesses/Work/redhat/results/pkg/watcher/results/results.go:81 +0xcf
github.com/tektoncd/results/pkg/watcher/reconciler/dynamic.(*Reconciler).Reconcile(0xc000d04f60, {0x4cb6780, 0xc000d04f90}, {0x4cd7af0, 0xc0004aec80})
    /home/ramesses/Work/redhat/results/pkg/watcher/reconciler/dynamic/dynamic.go:110 +0x56a
github.com/tektoncd/results/pkg/watcher/reconciler/pipelinerun.(*Reconciler).Reconcile(0xc000b3c1e0, {0x4cb6780, 0xc000d04f00}, {0xc000e00080, 0x10})
    /home/ramesses/Work/redhat/results/pkg/watcher/reconciler/pipelinerun/reconciler.go:100 +0xadf
knative.dev/pkg/controller.(*Impl).processNextWorkItem(0xc000b187e0)
    /home/ramesses/Work/redhat/results/vendor/knative.dev/pkg/controller/controller.go:542 +0x7b8
knative.dev/pkg/controller.(*Impl).RunContext.func3()
    /home/ramesses/Work/redhat/results/vendor/knative.dev/pkg/controller/controller.go:491 +0xab
created by knative.dev/pkg/controller.(*Impl).RunContext in goroutine 206
    /home/ramesses/Work/redhat/results/vendor/knative.dev/pkg/controller/controller.go:489 +0x5c5

/kind bug

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you review them:

Release Notes

NONE
tekton-robot commented 8 months ago

Hi @ramessesii2. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
ramessesii2 commented 8 months ago

@sayan-biswas @avinal fyi

sayan-biswas commented 8 months ago

@ramessesii2 This is the one we figured out yesterday, right?

ramessesii2 commented 8 months ago

This is the one we figured out yesterday, right?

Hey @sayan-biswas , yes!

sayan-biswas commented 8 months ago

This is the one we figured out yesterday, right?

Hey @sayan-biswas , yes!

Do you see this error after adding the nil check to Summary?

ramessesii2 commented 8 months ago

Do you see this error after adding the nil check to Summary?

Not so far! Do you suspect it's not the root cause?

enarha commented 7 months ago

Shouldn't you also add the same check here https://github.com/tektoncd/results/pull/702/files#diff-29c3f7e1287f6e99bc811ea3b6b08d62a6e8b4a43579530c50aed0f2ecd7de70R133 ?

ramessesii2 commented 7 months ago

Shouldn't you also add the same check here https://github.com/tektoncd/results/pull/702/files#diff-29c3f7e1287f6e99bc811ea3b6b08d62a6e8b4a43579530c50aed0f2ecd7de70R133 ?

Hey @enarha, the reason I didn't add the check for curr.Annotaions is because even if that is nil map, reading from a nil map is safe and it behaves as if the map is empty - if curr.Annotations is nil, the length check will return 0.

tekton-robot commented 7 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: avinal

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/tektoncd/results/blob/main/OWNERS)~~ [avinal] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
khrm commented 6 months ago

/cherry-pick @release-v0.9.x

khrm commented 6 months ago

/cherry-pick release-v0.9.x

tekton-robot commented 6 months ago

@khrm: cannot checkout @release-v0.9.x: error checking out @release-v0.9.x: exit status 1. output: error: pathspec '@release-v0.9.x' did not match any file(s) known to git

In response to [this](https://github.com/tektoncd/results/pull/702#issuecomment-2000061170): >/cherry-pick @release-v0.9.x Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
tekton-robot commented 6 months ago

@khrm: new pull request created: #733

In response to [this](https://github.com/tektoncd/results/pull/702#issuecomment-2000061720): > >/cherry-pick release-v0.9.x > > Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.