Skip to content

Commit 7cf643b

Browse files
authored
connectionTimeout respects net.Dialer default timeout (#1095)
1 parent f979c18 commit 7cf643b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pulsar/client_impl.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
)
3232

3333
const (
34-
defaultConnectionTimeout = 10 * time.Second
3534
defaultOperationTimeout = 30 * time.Second
3635
defaultKeepAliveInterval = 30 * time.Second
3736
defaultMemoryLimitBytes = 64 * 1024 * 1024
@@ -117,10 +116,10 @@ func newClient(options ClientOptions) (Client, error) {
117116
return nil, err
118117
}
119118

119+
// the default timeout respects Go's default timeout which is no timeout
120+
// Missing user specified timeout renders 0 values that matches
121+
// net.Dailer's default if time.Duration value is not initialized
120122
connectionTimeout := options.ConnectionTimeout
121-
if connectionTimeout.Nanoseconds() == 0 {
122-
connectionTimeout = defaultConnectionTimeout
123-
}
124123

125124
operationTimeout := options.OperationTimeout
126125
if operationTimeout.Nanoseconds() == 0 {

pulsar/internal/connection.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ func (c *connection) connect() bool {
256256

257257
if c.tlsOptions == nil {
258258
// Clear text connection
259-
cnx, err = net.DialTimeout("tcp", c.physicalAddr.Host, c.connectionTimeout)
259+
if c.connectionTimeout.Nanoseconds() > 0 {
260+
cnx, err = net.DialTimeout("tcp", c.physicalAddr.Host, c.connectionTimeout)
261+
} else {
262+
cnx, err = net.Dial("tcp", c.physicalAddr.Host)
263+
}
260264
} else {
261265
// TLS connection
262266
tlsConfig, err = c.getTLSConfig()
@@ -265,6 +269,8 @@ func (c *connection) connect() bool {
265269
return false
266270
}
267271

272+
// time.Duration is initialized to 0 by default, net.Dialer's default timeout is no timeout
273+
// therefore if c.connectionTimeout is 0, it means no timeout
268274
d := &net.Dialer{Timeout: c.connectionTimeout}
269275
cnx, err = tls.DialWithDialer(d, "tcp", c.physicalAddr.Host, tlsConfig)
270276
}

0 commit comments

Comments
 (0)