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

Nil Pointer error occurs when the Body is not set in http_helper.HttpDoOptions #1369

Closed
semihbkgr opened this issue Nov 6, 2023 · 0 comments · Fixed by #1370
Closed

Nil Pointer error occurs when the Body is not set in http_helper.HttpDoOptions #1369

semihbkgr opened this issue Nov 6, 2023 · 0 comments · Fixed by #1370
Labels
bug Something isn't working

Comments

@semihbkgr
Copy link
Contributor

semihbkgr commented Nov 6, 2023

Describe the bug
Calling certain functions in http_helper without a request body results in nil pointer dereference errors.

To Reproduce

doOpts := http_helper.HttpDoOptions{
	Method:    "GET",
	Url:       clientConf.ClientEndpoints.MembersAddresses,
	Headers:   headers,
	TlsConfig: nil,
	Timeout:   10,
	//Body: strings.NewReader(""), -> workaround
}
response := http_helper.HTTPDoWithRetryWithOptions(s.T(), doOpts, 200, 10, 10*time.Second)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x10490e7e8]

goroutine 6 [running]:
testing.tRunner.func1.2({0x104bae500, 0x104dd21e0})
	/usr/local/go/src/testing/testing.go:1545 +0x1c8
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1548 +0x360
panic({0x104bae500?, 0x104dd21e0?})
	/usr/local/go/src/runtime/panic.go:914 +0x218
io.ReadAll({0x0, 0x0})
	/usr/local/go/src/io/io.go:704 +0x58
github.com/gruntwork-io/terratest/modules/http-helper.HTTPDoWithRetryWithOptionsE({0x104c0a650, 0x140001544e0}, {{0x104aeadb2, 0x3}, {0x104b70e00, 0x0}, {0x0, 0x0}, 0x1400007f140, 0x0, ...}, ...)
	.../terratest/modules/http-helper/http_helper.go:351 +0x68
github.com/gruntwork-io/terratest/modules/http-helper.HTTPDoWithRetryWithOptions({0x104c0a650, 0x140001544e0}, {{0x104aeadb2, 0x3}, {0x104b70e00, 0x0}, {0x0, 0x0}, 0x1400007f140, 0x0, ...}, ...)
	.../terratest/modules/http-helper/http_helper.go:316 +0x64
...

Expected behavior
I would expect to call the function and send an HTTP request successfully without needing to set an empty noop reader body using strings.NewReader("") in the HttpDoOptions.

Versions

  • Terratest version: v0.41.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant