fix RunDialer: drain dial signals only after successful connect

This commit is contained in:
Jay
2026-05-20 08:19:46 -04:00
parent 09257e39b4
commit 8c7e3c3ee6
+10 -13
View File
@@ -532,24 +532,11 @@ func RunDialer(
case <-ctx.Done():
return
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 {
logger.Debug("dialer: dialing")
}
// dial a new connection
conn, err := connect(id, ctx, pool)
close(done)
// send error if dial failed and continue
if err != nil {
@@ -563,6 +550,16 @@ func RunDialer(
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
select {
case newConn <- conn: