Skip to content

Commit 8625e54

Browse files
committed
Excluded Close and Park methods from conn.Conn interface
1 parent c0d216d commit 8625e54

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 3.13.1
22
* Improved error messages
33
* Defended `cluster.balancer` with `sync.RWMutex` on `cluster.Insert`, `cluster.Update`, `cluster.Remove` and `cluster.Get`
4+
* Excluded `Close` and `Park` methods from `conn.Conn` interface
45

56
## 3.13.0
67
* Refactored `Connection` interface

internal/cluster/cluster.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,6 @@ func (c *cluster) Remove(ctx context.Context, e endpoint.Endpoint, opts ...crudO
382382
delete(c.index, e.Address())
383383
delete(c.endpoints, e.NodeID())
384384

385-
if entry.Conn != nil {
386-
// entry.Conn may be nil when connection is being tracked after unsuccessful dial().
387-
_ = entry.Conn.Close(ctx)
388-
}
389-
390385
return entry.Conn
391386
}
392387

internal/cluster/cluster_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func TestClusterFastRedial(t *testing.T) {
4646
done := make(chan struct{})
4747
go func() {
4848
for i := 0; i < size*10; i++ {
49-
c, err := c.Get(context.Background())
49+
cc, err := c.Get(context.Background())
5050
// enforce close bad connects to track them
51-
if err == nil && c != nil && c.Endpoint().Address() == "bad:0" {
52-
_ = c.Close(ctx)
51+
if err == nil && c != nil && cc.Endpoint().Address() == "bad:0" {
52+
_ = c.Remove(ctx, cc.Endpoint())
5353
}
5454
}
5555
close(done)

internal/conn/conn.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ type Conn interface {
3737
IsState(states ...State) bool
3838
GetState() State
3939
SetState(State) State
40-
41-
Close(ctx context.Context) error
42-
Park(ctx context.Context) error
4340
}
4441

4542
func (c *conn) Address() string {
@@ -56,7 +53,7 @@ type conn struct {
5653
state State
5754
usages int32
5855
ttl timeutil.Timer
59-
onClose []func(Conn)
56+
onClose []func(*conn)
6057
}
6158

6259
func (c *conn) IsState(states ...State) bool {
@@ -426,21 +423,21 @@ func (c *conn) NewStream(
426423

427424
type option func(c *conn)
428425

429-
func withOnClose(onClose func(Conn)) option {
426+
func withOnClose(onClose func(*conn)) option {
430427
return func(c *conn) {
431428
if onClose != nil {
432429
c.onClose = append(c.onClose, onClose)
433430
}
434431
}
435432
}
436433

437-
func New(e endpoint.Endpoint, config Config, opts ...option) Conn {
434+
func newConn(e endpoint.Endpoint, config Config, opts ...option) *conn {
438435
c := &conn{
439436
state: Created,
440437
endpoint: e,
441438
config: config,
442439
done: make(chan struct{}),
443-
onClose: make([]func(Conn), 0),
440+
onClose: make([]func(*conn), 0),
444441
}
445442
for _, o := range opts {
446443
o(c)
@@ -450,3 +447,7 @@ func New(e endpoint.Endpoint, config Config, opts ...option) Conn {
450447
}
451448
return c
452449
}
450+
451+
func New(e endpoint.Endpoint, config Config, opts ...option) Conn {
452+
return newConn(e, config, opts...)
453+
}

internal/conn/pool.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type pool struct {
4646
config Config
4747
mtx sync.RWMutex
4848
opts []grpc.DialOption
49-
conns map[string]Conn
49+
conns map[string]*conn
5050
done chan struct{}
5151
}
5252

@@ -101,10 +101,10 @@ func (p *pool) GetConn(e endpoint.Endpoint) Conn {
101101
if cc, ok := p.conns[e.Address()]; ok {
102102
return cc
103103
}
104-
cc := New(
104+
cc := newConn(
105105
e,
106106
p.config,
107-
withOnClose(func(c Conn) {
107+
withOnClose(func(c *conn) {
108108
// conn.Conn.Close() must called on under locked p.mtx
109109
delete(p.conns, c.Endpoint().Address())
110110
}),
@@ -141,7 +141,7 @@ func NewPool(
141141
usages: 1,
142142
config: config,
143143
opts: config.GrpcDialOptions(),
144-
conns: make(map[string]Conn),
144+
conns: make(map[string]*conn),
145145
done: make(chan struct{}),
146146
}
147147
if ttl := config.ConnectionTTL(); ttl > 0 {

0 commit comments

Comments
 (0)