fix(bondclient): слать Hello с реальным числом lane после фильтрации
Открыть все кандидатные стримы сначала, затем писать Hello с len(opened), чтобы bondserver.waitForInitialLanes не зависал на lane, которые никогда не открывались (закрыты/ошибка). Также документирует, почему клиентский write-retry не зацикливается как серверный: набор lane клиента фиксирован на время жизни Handle.
This commit is contained in:
1 parent
6588544368
commit
ac695603b7
1 file changed
+27
-10
@@ -55,9 +55,15 @@ func (h *Handler) Handle(ctx context.Context, tcpConn net.Conn, connID uint64, c
|
|||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
lanes := make([]*lane, 0, len(candidates))
|
// Phase 1: open streams on usable sessions. Phase 2: send Hello with the
|
||||||
laneIDs := make([]string, 0, len(candidates))
|
// actual lane count so bondserver.waitForInitialLanes doesn't wait on lanes
|
||||||
for i, ps := range candidates {
|
// that were never opened.
|
||||||
|
type pending struct {
|
||||||
|
ps *tcpfwd.PooledSession
|
||||||
|
stream *smux.Stream
|
||||||
|
}
|
||||||
|
opened := make([]pending, 0, len(candidates))
|
||||||
|
for _, ps := range candidates {
|
||||||
if ps.Sess.IsClosed() {
|
if ps.Sess.IsClosed() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -66,15 +72,22 @@ func (h *Handler) Handle(ctx context.Context, tcpConn net.Conn, connID uint64, c
|
|||||||
h.Deps.log().Errorf("[bond %d] session %d open stream error: %s", connID, ps.ID, err)
|
h.Deps.log().Errorf("[bond %d] session %d open stream error: %s", connID, ps.ID, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := bondframe.WriteHello(stream, connID, uint16(i), uint16(len(candidates))); err != nil {
|
opened = append(opened, pending{ps: ps, stream: stream})
|
||||||
h.Deps.log().Errorf("[bond %d] session %d hello error: %s", connID, ps.ID, err)
|
}
|
||||||
_ = stream.Close()
|
|
||||||
|
lanes := make([]*lane, 0, len(opened))
|
||||||
|
laneIDs := make([]string, 0, len(opened))
|
||||||
|
laneCount := uint16(len(opened))
|
||||||
|
for i, p := range opened {
|
||||||
|
if err := bondframe.WriteHello(p.stream, connID, uint16(i), laneCount); err != nil {
|
||||||
|
h.Deps.log().Errorf("[bond %d] session %d hello error: %s", connID, p.ps.ID, err)
|
||||||
|
_ = p.stream.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ps.Opened.Add(1)
|
p.ps.Opened.Add(1)
|
||||||
ps.Active.Add(1)
|
p.ps.Active.Add(1)
|
||||||
lanes = append(lanes, &lane{ps: ps, stream: stream})
|
lanes = append(lanes, &lane{ps: p.ps, stream: p.stream})
|
||||||
laneIDs = append(laneIDs, strconv.Itoa(ps.ID))
|
laneIDs = append(laneIDs, strconv.Itoa(p.ps.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(lanes) == 0 {
|
if len(lanes) == 0 {
|
||||||
@@ -190,6 +203,10 @@ func (h *Handler) copyTCPToBond(ctx context.Context, connID uint64, tcpConn net.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeBondFrameToNextLane writes to the next live lane in round-robin order.
|
||||||
|
// Unlike bondserver.writeToNextLane (which loops waiting for new lanes to
|
||||||
|
// attach), the client's lane set is fixed for the lifetime of Handle, so once
|
||||||
|
// all lanes are dead there is nothing to wait for — fail fast.
|
||||||
func writeBondFrameToNextLane(ctx context.Context, lanes []*lane, typ byte, seq uint64, data []byte, laneIdx *uint64) (*lane, error) {
|
func writeBondFrameToNextLane(ctx context.Context, lanes []*lane, typ byte, seq uint64, data []byte, laneIdx *uint64) (*lane, error) {
|
||||||
for range lanes {
|
for range lanes {
|
||||||
idx := *laneIdx % uint64(len(lanes))
|
idx := *laneIdx % uint64(len(lanes))
|
||||||
|
|||||||
Reference in new issue
Block a user