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

restful protocol transport dial cause io timeout #2302

Open
otis95 opened this issue Apr 14, 2023 · 1 comment
Open

restful protocol transport dial cause io timeout #2302

otis95 opened this issue Apr 14, 2023 · 1 comment

Comments

@otis95
Copy link

otis95 commented Apr 14, 2023

Environment

  • Client: Dubbo-go, v1.5.9
  • Protocol: rest
  • Registry: zookeeper

Issue description

https://github.com/apache/dubbo-go/blob/main/protocol/rest/client/client_impl/resty_client.go#L59
err = c.SetDeadline(time.Now().Add(restOption.RequestTimeout))
http连接池复用tcp连接时,因为设置了deadline,resp未返回直接抛出io timeout。

@otis95
Copy link
Author

otis95 commented Apr 14, 2023

推荐调整为:

func NewRestyClient(restOption *client.RestOptions) client.RestClient {
	client := resty.New()
	client.SetTransport(
		&http.Transport{
			DialContext: (&net.Dialer{
				Timeout: restOption.ConnectTimeout,
			}).DialContext,
			IdleConnTimeout: 90 * time.Second,
		}).SetTimeout(restOption.RequestTimeout)
	return &RestyClient{
		client: client,
	}
}
  1. 通过配置IdleConnTimeout超时来回收空闲链接。
  2. 通过client.SetTimeout来设置每次请求的超时时间。

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

No branches or pull requests

1 participant