Skip to content

Commit

Permalink
Inject Dialer from ClusterConfig (apache#1376)
Browse files Browse the repository at this point in the history
Initialize dialer during creating ClusterConfig

Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
  • Loading branch information
rinx authored and alourie committed Jan 21, 2020
1 parent 617765a commit 95d072f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ Karl Matthias <karl@matthias.org>
Thomas Meson <zllak@hycik.org>
Martin Sucha <martin.sucha@kiwi.com>; <git@mm.ms47.eu>
Pavel Buchinchik <p.buchinchik@gmail.com>
Rintaro Okamura <rintaro.okamura@gmail.com>
4 changes: 4 additions & 0 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ type ClusterConfig struct {
// (default: 200 microseconds)
WriteCoalesceWaitTime time.Duration

// Dialer will be used to establish all connections created for this Cluster.
// If not provided, a default dialer configured with ConnectTimeout will be used.
Dialer *net.Dialer

// internal config for testing
disableControlConn bool
}
Expand Down
9 changes: 7 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type ConnConfig struct {
CQLVersion string
Timeout time.Duration
ConnectTimeout time.Duration
Dialer *net.Dialer
Compressor Compressor
Authenticator Authenticator
AuthProvider func(h *HostInfo) (Authenticator, error)
Expand Down Expand Up @@ -200,9 +201,13 @@ func (s *Session) dialWithoutObserver(ctx context.Context, host *HostInfo, cfg *
panic(fmt.Sprintf("host missing port: %v", port))
}

dialer := &net.Dialer{
Timeout: cfg.ConnectTimeout,
dialer := cfg.Dialer
if dialer == nil {
dialer = &net.Dialer{
Timeout: cfg.ConnectTimeout,
}
}

if cfg.Keepalive > 0 {
dialer.KeepAlive = cfg.Keepalive
}
Expand Down
1 change: 1 addition & 0 deletions connectionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func connConfig(cfg *ClusterConfig) (*ConnConfig, error) {
CQLVersion: cfg.CQLVersion,
Timeout: cfg.Timeout,
ConnectTimeout: cfg.ConnectTimeout,
Dialer: cfg.Dialer,
Compressor: cfg.Compressor,
Authenticator: cfg.Authenticator,
AuthProvider: cfg.AuthProvider,
Expand Down

0 comments on commit 95d072f

Please sign in to comment.