Add transport dial timeout
This commit is contained in:
@@ -20,6 +20,7 @@ type Options struct {
|
||||
Wrappers []Wrapper
|
||||
Retries int
|
||||
RequestTimeout time.Duration
|
||||
DialTimeout time.Duration
|
||||
|
||||
// Other options to be used by client implementations
|
||||
Options map[string]string
|
||||
@@ -49,6 +50,7 @@ func newOptions(options ...Option) Options {
|
||||
Codecs: make(map[string]codec.NewCodec),
|
||||
Retries: DefaultRetries,
|
||||
RequestTimeout: DefaultRequestTimeout,
|
||||
DialTimeout: transport.DefaultDialTimeout,
|
||||
}
|
||||
|
||||
for _, o := range options {
|
||||
@@ -145,6 +147,13 @@ func RequestTimeout(d time.Duration) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Transport dial timeout
|
||||
func DialTimeout(d time.Duration) Option {
|
||||
return func(o *Options) {
|
||||
o.DialTimeout = d
|
||||
}
|
||||
}
|
||||
|
||||
// Call Options
|
||||
|
||||
func WithSelectOption(so selector.SelectOption) CallOption {
|
||||
|
||||
@@ -70,7 +70,7 @@ func (r *rpcClient) call(ctx context.Context, address string, request Request, r
|
||||
return errors.InternalServerError("go.micro.client", err.Error())
|
||||
}
|
||||
|
||||
c, err := r.opts.Transport.Dial(address)
|
||||
c, err := r.opts.Transport.Dial(address, transport.WithTimeout(r.opts.DialTimeout))
|
||||
if err != nil {
|
||||
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (r *rpcClient) stream(ctx context.Context, address string, req Request) (St
|
||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
||||
}
|
||||
|
||||
c, err := r.opts.Transport.Dial(address, transport.WithStream())
|
||||
c, err := r.opts.Transport.Dial(address, transport.WithStream(), transport.WithTimeout(r.opts.DialTimeout))
|
||||
if err != nil {
|
||||
return nil, errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user