fix RunDialer: drain dial signals only after successful connect
This commit is contained in:
+10
-13
@@ -532,24 +532,11 @@ func RunDialer(
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-dial:
|
case <-dial:
|
||||||
// drain dial signals while connection is being established
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-dial:
|
|
||||||
case <-done:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if logger != nil {
|
if logger != nil {
|
||||||
logger.Debug("dialer: dialing")
|
logger.Debug("dialer: dialing")
|
||||||
}
|
}
|
||||||
// dial a new connection
|
// dial a new connection
|
||||||
conn, err := connect(id, ctx, pool)
|
conn, err := connect(id, ctx, pool)
|
||||||
close(done)
|
|
||||||
|
|
||||||
// send error if dial failed and continue
|
// send error if dial failed and continue
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -563,6 +550,16 @@ func RunDialer(
|
|||||||
logger.Debug("dialer: connected")
|
logger.Debug("dialer: connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// drain any redundant signals that arrived during the dial
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-dial:
|
||||||
|
default:
|
||||||
|
goto drained
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drained:
|
||||||
|
|
||||||
// send the new connection or close and exit
|
// send the new connection or close and exit
|
||||||
select {
|
select {
|
||||||
case newConn <- conn:
|
case newConn <- conn:
|
||||||
|
|||||||
Reference in New Issue
Block a user