Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

transport: pool, stop shard refill faster when context is done #291

@Kulezi

Description

@Kulezi

Checking if context is done should be checked in the loop, returning early without relying on the result of OpenShardConn.

func (r *PoolRefiller) fill(ctx context.Context) {
if !r.needsFilling() {
return
}
si := ShardInfo{
NrShards: uint16(r.pool.nrShards),
MsbIgnore: r.pool.msbIgnore,
}
for i := 0; i < r.pool.nrShards; i++ {
if r.pool.loadConn(i) != nil {
continue
}
si.Shard = uint16(i)
span := startSpan()
conn, err := OpenShardConn(ctx, r.addr, si, r.cfg)
span.stop()
if err != nil {
if r.pool.connObs != nil {
r.pool.connObs.OnConnect(ConnectEvent{ConnEvent: ConnEvent{Addr: r.addr, Shard: si.Shard}, span: span, Err: err})
}
if conn != nil {
conn.Close()
}
continue
}
if r.pool.connObs != nil {
r.pool.connObs.OnConnect(ConnectEvent{ConnEvent: conn.Event(), span: span})
}
if conn.Shard() != i {
log.Fatalf("opened conn to wrong shard: expected %d got %d", i, conn.Shard())
}
conn.setOnClose(r.onConnClose)
r.pool.storeConn(conn)
r.active++
if !r.needsFilling() {
return
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions