@@ -33,7 +33,7 @@ func NewServiceClient(svc Service, clientCfg *ClientCommonConf) *ServiceClient {
3333 svc : svc ,
3434 cfg : clientCfg ,
3535 client : & http.Client {
36- Timeout : 5 * time .Second ,
36+ Timeout : time . Duration ( clientCfg . RequestTimeout * int64 ( time .Second )) ,
3737 },
3838 stopCh : make (chan struct {}),
3939 }
@@ -51,7 +51,7 @@ func NewServiceClient(svc Service, clientCfg *ClientCommonConf) *ServiceClient {
5151 }
5252 if c .listenProxy () {
5353 c .pClient = & http.Client {
54- Timeout : 5 * time .Second ,
54+ Timeout : time . Duration ( clientCfg . RequestTimeout * int64 ( time .Second )) ,
5555 Transport : & http.Transport {
5656 Proxy : nil ,
5757 DialContext : c .DialProxyAddr ,
@@ -297,13 +297,29 @@ func (c *ServiceClient) refreshAPI(ctx context.Context) error {
297297}
298298
299299// Use the binded address to dial
300- func (c * ServiceClient ) DialBindAddr (_ context.Context , network string , addr string ) (net.Conn , error ) {
301- return reuse .Dial ("tcp" , c .listener .Addr ().String (), addr )
300+ func (c * ServiceClient ) DialBindAddr (ctx context.Context , network string , addr string ) (net.Conn , error ) {
301+ nla , err := reuse .ResolveAddr (network , c .listener .Addr ().String ())
302+ if err != nil {
303+ return nil , fmt .Errorf ("failed to resolve local addr: %w" , err )
304+ }
305+ d := net.Dialer {
306+ Control : reuse .Control ,
307+ LocalAddr : nla ,
308+ }
309+ return d .DialContext (ctx , network , addr )
302310}
303311
304312// Use the binded address to dial
305- func (c * ServiceClient ) DialProxyAddr (_ context.Context , network string , addr string ) (net.Conn , error ) {
306- return reuse .Dial ("tcp" , c .pListener .Addr ().String (), addr )
313+ func (c * ServiceClient ) DialProxyAddr (ctx context.Context , network string , addr string ) (net.Conn , error ) {
314+ nla , err := reuse .ResolveAddr (network , c .pListener .Addr ().String ())
315+ if err != nil {
316+ return nil , fmt .Errorf ("failed to resolve local addr: %w" , err )
317+ }
318+ d := net.Dialer {
319+ Control : reuse .Control ,
320+ LocalAddr : nla ,
321+ }
322+ return d .DialContext (ctx , network , addr )
307323}
308324
309325func (c * ServiceClient ) Start (force bool ) error {
0 commit comments