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

panic when URL address is down #873

Closed
deferbot opened this issue Sep 26, 2024 · 3 comments · Fixed by #872
Closed

panic when URL address is down #873

deferbot opened this issue Sep 26, 2024 · 3 comments · Fixed by #872
Labels

Comments

@deferbot
Copy link

if URL address is down, call panics on v2.15.2, on v2.14.0 it works ok.

with v2.15.2:

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=0x104d74e5c]

goroutine 1 [running]:
github.com/go-resty/resty/v2.(*Request).Execute.func1()
	/Users/deferbot/go/pkg/mod/github.com/go-resty/resty/[email protected]/request.go:995 +0x134
panic({0x104e561c0?, 0x105086270?})
	/opt/homebrew/Cellar/go/1.23.1/libexec/src/runtime/panic.go:785 +0x124
github.com/go-resty/resty/v2.responseLogger(0x14000164288, 0x14000096050)
	/Users/deferbot/go/pkg/mod/github.com/go-resty/resty/[email protected]/middleware.go:378 +0x29c
github.com/go-resty/resty/v2.(*Client).execute(0x14000164288, 0x1400018a000)
	/Users/deferbot/go/pkg/mod/github.com/go-resty/resty/[email protected]/client.go:1247 +0x258
github.com/go-resty/resty/v2.(*Request).Execute(0x1400018a000, {0x104d7df60?, 0x104d7e509?}, {0x104d7f161, 0x8})
	/Users/deferbot/go/pkg/mod/github.com/go-resty/resty/[email protected]/request.go:1019 +0x520
github.com/go-resty/resty/v2.(*Request).Get(...)
	/Users/deferbot/go/pkg/mod/github.com/go-resty/resty/[email protected]/request.go:935
main.main()
	/Users/deferbot/develop/tests/resty-error/main.go:31 +0x464


with v2.14.0:

2024/09/26 12:01:13 Get "http://64.5.122.227:3040/7185551212": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

This is the sample code:

package main

import (
	"context"
	"log"
	"time"

	"github.com/go-resty/resty/v2"
)

type phoneData struct {
	T string `json:"phone,omitempty"`
	P int    `json:"provider,omitempty"`
}

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*6)
	defer cancel()

	c := resty.New().
		SetDebug(true).
		SetTimeout(3 * time.Second).
		SetBaseURL("http://64.5.122.227:3040").
		SetHeaders(map[string]string{
			"Content-Type": "application/json; charset=utf-8",
			"User-Agent":   "utd.store",
		})

	body := phoneData{}

	resp, err := c.R().SetContext(ctx).SetResult(&body).SetPathParam("phone", "7185551212").Get("/{phone}")
	if err != nil {
		log.Fatal(err)
	}

	if resp.IsError() {
		log.Fatal(resp.Error())
	}

	log.Printf("body: %+v\n", body)
}

@jeevatkm
Copy link
Member

jeevatkm commented Sep 26, 2024

@deferbot Thanks for reaching out. Coincidently, @matlockx submitted a PR to address this nil panic with #872

I will release v2.15.3 once I get home. Thanks.

@jeevatkm
Copy link
Member

jeevatkm commented Sep 26, 2024

@deferbot I was able to make the release prep work on the browser. Now, v2.15.3 has been released.

@deferbot
Copy link
Author

Great, it is working now with v2.15.3.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants