Skip to content

net/http: better error with nil *http.Client #53521

Closed as not planned
Closed as not planned
@kevinburkesegment

Description

@kevinburkesegment

Currently, if I try to issue a HTTP request with a nil *http.Client, I get a fairly inscrutable error message - here's a sample from the aws-sdk-go library. My initial thought was the library did something wrong with timeouts.

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

goroutine 35 [running]:
net/http.(*Client).deadline(0xb75780?)
	/usr/local/go/src/net/http/client.go:189 +0x14
net/http.(*Client).do(0x0, 0xc000440300)
	/usr/local/go/src/net/http/client.go:611 +0x225
net/http.(*Client).Do(...)
	/usr/local/go/src/net/http/client.go:593
github.com/aws/aws-sdk-go/aws/corehandlers.sendFollowRedirects(0xc0a54e5cabd8ad81?)
	/src/vendor/github.com/aws/aws-sdk-go/aws/corehandlers/handlers.go:120 +0x27
github.com/aws/aws-sdk-go/aws/corehandlers.glob..func3(0xc000442500)
	/src/vendor/github.com/aws/aws-sdk-go/aws/corehandlers/handlers.go:112 +0x176 

The actual problem is that we are trying to make a HTTP request with a nil http.Client, which you can reproduce with the following two lines.

	var client *http.Client
	client.Get("http://jsonip.com")

What do you think about adding a nil check inside *Client.do(), and then panicking with a better error message?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions