Merge pull request #1419 from lsytj0413/fix-default-dialtimeout

feat(option): default dialtimeout take effect when dialer is nil
This commit is contained in:
Vladimir Mihailenco 2020-07-24 16:21:00 +03:00 committed by GitHub
commit dd8e70ad43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -120,6 +120,9 @@ func (opt *Options) init() {
opt.Network = "tcp" opt.Network = "tcp"
} }
} }
if opt.DialTimeout == 0 {
opt.DialTimeout = 5 * time.Second
}
if opt.Dialer == nil { if opt.Dialer == nil {
opt.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) { opt.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
netDialer := &net.Dialer{ netDialer := &net.Dialer{
@ -135,9 +138,6 @@ func (opt *Options) init() {
if opt.PoolSize == 0 { if opt.PoolSize == 0 {
opt.PoolSize = 10 * runtime.NumCPU() opt.PoolSize = 10 * runtime.NumCPU()
} }
if opt.DialTimeout == 0 {
opt.DialTimeout = 5 * time.Second
}
switch opt.ReadTimeout { switch opt.ReadTimeout {
case -1: case -1:
opt.ReadTimeout = 0 opt.ReadTimeout = 0