Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue 1094] connectionTimeout respects net.Dialer default timeout #1095

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pulsar/client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
)

const (
defaultConnectionTimeout = 10 * time.Second
defaultOperationTimeout = 30 * time.Second
defaultKeepAliveInterval = 30 * time.Second
defaultMemoryLimitBytes = 64 * 1024 * 1024
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion pulsar/internal/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down