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

fix panic in github interceptor #357

Merged
merged 1 commit into from
Jan 22, 2020
Merged

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented Jan 17, 2020

Changes

We were passing the original request where the body had been drained
to the first interceptor meaning that the body to the first interceptor
in the chain was always empty. Further, we were using the GetBody which
can sometimes be empty leading to a panic.

fixes #355

Submitter Checklist

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

See the contribution guide for more details.

Release Notes

Fixes bug that caused panic when Github interceptor was used as the first interceptor

@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 17, 2020
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 17, 2020
@dibyom dibyom force-pushed the panic branch 2 times, most recently from a3c6b94 to b2535aa Compare January 17, 2020 23:07
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 17, 2020
@dibyom dibyom marked this pull request as ready for review January 17, 2020 23:31
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 17, 2020
@bobcatfish
Copy link
Collaborator

tektoncd/plumbing#186 is hitting here too :(

@vdemeester
Copy link
Member

/retest
@dibyom can you update the release not part of the PR description ? 😛

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 20, 2020
@@ -231,6 +231,189 @@ func TestHandleEvent(t *testing.T) {
}
}

func TestHandleEventWithInterceptors(t *testing.T) {
Copy link

Choose a reason for hiding this comment

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

This is repeating TestHandleEvent with only a few differences. We could use a testing table so that we could test [0-2] interceptors in a bit less verbose way. This seems fine though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah long term, I want to extract the common bits out into a couple of helper methods that create the required resources, and the clients (like we do in the reconciler tests in pipeline). For this PR though, I wanted to keep the non-fix changes to a minimum

Copy link

@vtereso vtereso left a comment

Choose a reason for hiding this comment

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

Ran a manual test and also good 👍

}
defer body.Close()
payload, err := ioutil.ReadAll(body)
defer request.Body.Close()
Copy link
Member

@wlynch wlynch Jan 21, 2020

Choose a reason for hiding this comment

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

This still runs the risk of panicking if request or Body is nil. We probably want to have checks here to handle gracefully.

Example - https://play.golang.org/p/HstyZm09vuE

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point; let me add some checks

Copy link
Member Author

@dibyom dibyom Jan 21, 2020

Choose a reason for hiding this comment

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

testing this is going to require us to refactor our tests a bit...gonna make this a new commit in this PR!

fixed! PTAL

We were passing the original request where the body had been drained
to the first interceptor meaning that the body to the first interceptor
in the chain was always empty. Further, we were using the `GetBody` which
can sometimes be empty leading to a panic.

fixes tektoncd#355

Signed-off-by: Dibyo Mukherjee <[email protected]>
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 21, 2020
@dibyom dibyom added this to the Triggers 0.2.1 milestone Jan 21, 2020
Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

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

/lgtm

payload, err := ioutil.ReadAll(body)
if err != nil {
return nil, fmt.Errorf("error reading request body: %w", err)
var payload = []byte(`{}`)
Copy link
Member

Choose a reason for hiding this comment

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

I don't feel too strongly about this, but should we be consistent with the webhook handler and default to []byte{}?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we'd have to do it the other way around though since makeCelEnv errors out if you pass it []byte{}

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 22, 2020
@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester, wlynch

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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 22, 2020
@tekton-robot tekton-robot merged commit 63f3bad into tektoncd:master Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid memory address or nil pointer dereference on v0.2.0
6 participants