This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new 7cf643be connectionTimeout respects net.Dialer default timeout (#1095)
7cf643be is described below
commit 7cf643be20b0eed9b37e168d04884e89f534efdd
Author: ming <[email protected]>
AuthorDate: Fri Sep 15 11:32:28 2023 -0400
connectionTimeout respects net.Dialer default timeout (#1095)
---
pulsar/client_impl.go | 7 +++----
pulsar/internal/connection.go | 8 +++++++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/pulsar/client_impl.go b/pulsar/client_impl.go
index 801eab3f..7daf6f62 100644
--- a/pulsar/client_impl.go
+++ b/pulsar/client_impl.go
@@ -31,7 +31,6 @@ import (
)
const (
- defaultConnectionTimeout = 10 * time.Second
defaultOperationTimeout = 30 * time.Second
defaultKeepAliveInterval = 30 * time.Second
defaultMemoryLimitBytes = 64 * 1024 * 1024
@@ -117,10 +116,10 @@ func newClient(options ClientOptions) (Client, error) {
return nil, err
}
+ // the default timeout respects Go's default timeout which is no timeout
+ // Missing user specified timeout renders 0 values that matches
+ // net.Dailer's default if time.Duration value is not initialized
connectionTimeout := options.ConnectionTimeout
- if connectionTimeout.Nanoseconds() == 0 {
- connectionTimeout = defaultConnectionTimeout
- }
operationTimeout := options.OperationTimeout
if operationTimeout.Nanoseconds() == 0 {
diff --git a/pulsar/internal/connection.go b/pulsar/internal/connection.go
index e2ae7ac8..840ecc4f 100644
--- a/pulsar/internal/connection.go
+++ b/pulsar/internal/connection.go
@@ -256,7 +256,11 @@ func (c *connection) connect() bool {
if c.tlsOptions == nil {
// Clear text connection
- cnx, err = net.DialTimeout("tcp", c.physicalAddr.Host,
c.connectionTimeout)
+ if c.connectionTimeout.Nanoseconds() > 0 {
+ cnx, err = net.DialTimeout("tcp", c.physicalAddr.Host,
c.connectionTimeout)
+ } else {
+ cnx, err = net.Dial("tcp", c.physicalAddr.Host)
+ }
} else {
// TLS connection
tlsConfig, err = c.getTLSConfig()
@@ -265,6 +269,8 @@ func (c *connection) connect() bool {
return false
}
+ // time.Duration is initialized to 0 by default, net.Dialer's
default timeout is no timeout
+ // therefore if c.connectionTimeout is 0, it means no timeout
d := &net.Dialer{Timeout: c.connectionTimeout}
cnx, err = tls.DialWithDialer(d, "tcp", c.physicalAddr.Host,
tlsConfig)
}