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

--log-http consumes the Request Body, making it invalid #377

Closed
Harwayne opened this issue Aug 19, 2019 · 0 comments · Fixed by #378
Closed

--log-http consumes the Request Body, making it invalid #377

Harwayne opened this issue Aug 19, 2019 · 0 comments · Fixed by #378
Labels
kind/bug Categorizes issue or PR as related to a bug.
Milestone

Comments

@Harwayne
Copy link
Contributor

In what area(s)?

What version of Knative Client?

Version: v20190819-local-dccaf36
Build Date: 2019-08-19 22:55:23
Git Revision: dccaf36
Support:

  • Serving: v0.8.0 v0.7.1
  • API(s): v1alpha1

Expected Behavior

I expect that adding the --log-http flag to a command makes no difference to the request the server sees.

Actual Behavior

Adding the --log-http flag will send empty bodies in all requests (with incorrect content-length headers to boot).

Expected Cause


Copies the request. Importantly, Request's Body is an interface and therefore a pass by reference. Body can only be read once, so

reqBytes, _ := httputil.DumpRequestOut(&reqCopy, true)

drains the body for both r and reqCopy. It then sets a copy for reqCopy.

Steps to Reproduce the Problem

Logs:

 ./kn service create --log-http foo --image foo.bar 
===== REQUEST =====
GET /apis/serving.knative.dev/v1alpha1/namespaces/default/services/foo HTTP/1.1
Host: 35.222.62.54
User-Agent: kn/v0.0.0 (linux/amd64) kubernetes/$Format
Accept: application/json, */*
Authorization: *******************************************************************************************************************************************                                                
Accept-Encoding: gzip


===== RESPONSE =====
HTTP/2.0 404 Not Found
Content-Length: 232
Audit-Id: a032637e-a483-4232-abfd-2ed69beae461
Content-Type: application/json
Date: Mon, 19 Aug 2019 22:56:35 GMT

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"services.serving.knative.dev \"foo\" not found","reason":"NotFound","details":{"name":"foo","group":"serving.knative.dev","kind":"services"},"code":404}

 * * * * * *
===== REQUEST =====
POST /apis/serving.knative.dev/v1alpha1/namespaces/default/services HTTP/1.1
Host: 35.222.62.54
User-Agent: kn/v0.0.0 (linux/amd64) kubernetes/$Format
Content-Length: 298
Accept: application/json, */*
Authorization: *******************************************************************************************************************************************                                                
Content-Type: application/json
Accept-Encoding: gzip

{"kind":"Service","apiVersion":"serving.knative.dev/v1alpha1","metadata":{"name":"foo","namespace":"default","creationTimestamp":null},"spec":{"template":{"metadata":{"name":"foo-wtltm-1","creationTimestamp":null},"spec":{"containers":[{"name":"","image":"foo.bar","resources":{}}]}}},"status":{}}

===== RESPONSE =====
HTTP/2.0 500 Internal Server Error
Content-Length: 156
Audit-Id: ea98f490-abaf-47f3-a445-150a9c2d120b
Content-Type: application/json
Date: Mon, 19 Aug 2019 22:56:35 GMT

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"request declared a Content-Length of 298 but only wrote 0 bytes","code":500}                                               

 * * * * * *

This was followed by an unrelated panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x116bb94]

goroutine 1 [running]:
knative.dev/client/pkg/errors.isCRDError(0x7f748f7b1208, 0xc000264120, 0xc000264120)
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/pkg/errors/factory.go:25 +0x74                                                                                                   
knative.dev/client/pkg/errors.GetError(0x15986c0, 0xc000264120, 0xc0003e2000, 0x15986c0)
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/pkg/errors/factory.go:44 +0x8f                                                                                                   
knative.dev/client/pkg/serving/v1alpha1.(*knClient).CreateService(0xc000310260, 0xc0001eae00, 0x915503, 0xc0002a8280)                                                                                     
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/pkg/serving/v1alpha1/client.go:174 +0x84                                                                                         
knative.dev/client/pkg/kn/commands/service.createService(0x15e6800, 0xc000310260, 0xc0001eae00, 0x13dd649, 0x7, 0x1599000, 0xc000010018, 0x0, 0x0)                                                        
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/pkg/kn/commands/service/service_create.go:136 +0x4b                                                                              
knative.dev/client/pkg/kn/commands/service.NewServiceCreateCommand.func1(0xc0002a8c80, 0xc0002a2ac0, 0x1, 0x4, 0x0, 0x0)                                                                                  
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/pkg/kn/commands/service/service_create.go:100 +0x6e2                                                                             
github.com/spf13/cobra.(*Command).execute(0xc0002a8c80, 0xc0002a2a80, 0x4, 0x4, 0xc0002a8c80, 0xc0002a2a80)                                                                                               
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/vendor/github.com/spf13/cobra/command.go:762 +0x465                                                                              
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002a8280, 0x15bc74fbd460474b, 0x206aa20, 0x51cddf)
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/vendor/github.com/spf13/cobra/command.go:852 +0x2ec                                                                              
github.com/spf13/cobra.(*Command).Execute(...)
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/vendor/github.com/spf13/cobra/command.go:800                                                                                     
main.main()
        /usr/local/google/home/harwayne/go-mod/github.com/knative/client/cmd/kn/main.go:36 +0xb6
@Harwayne Harwayne added the kind/bug Categorizes issue or PR as related to a bug. label Aug 19, 2019
@navidshaikh navidshaikh added this to the v0.8.0 milestone Aug 27, 2019
navidshaikh pushed a commit to navidshaikh/client that referenced this issue Jun 19, 2020
dsimansk added a commit to dsimansk/client that referenced this issue May 15, 2024
* [release-v1.12] Add func ld flags file

* Update S-O branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants