mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
transport: a barrier that fails on its connection drops it
A send or receive failure left session.conn in place, so a caller that does not invalidate the session (the store learner) reused the dead socket on every retry and never learned a restarted replica's store. The barrier now detaches and closes the connection, as the catch-up and rebuild senders do; the next barrier re-dials. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c7cff76f00
commit
353df5993e
2 files changed
+55
No files matched your search
@@ -113,3 +113,50 @@ func TestStoreLearnerDoesNotRaceTheFirstWrites(t *testing.T) {
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// The learner's barrier connects but its read fails (the replica's process
|
||||
// accepts and drops the connection, then restarts). The broken connection
|
||||
// must not be reused: the next attempt re-dials and learns the store.
|
||||
func TestStoreLearnerRedialsAfterABrokenConnection(t *testing.T) {
|
||||
drop, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
addr := drop.Addr().String()
|
||||
go func() {
|
||||
for {
|
||||
c, err := drop.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_ = c.Close() // connected, then the read fails
|
||||
}
|
||||
}()
|
||||
v := NewReplicationVolume("v", storage.NewBlockStore(64, 4096))
|
||||
defer v.Close()
|
||||
v.RequireAttestedStores()
|
||||
if err := v.UpdateReplicaSet(1, []ReplicaTarget{{ReplicaID: "r2", DataAddr: addr, ControlAddr: addr, Epoch: 1, EndpointVersion: 1}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(400 * time.Millisecond) // a few connected, failed attempts
|
||||
_ = drop.Close()
|
||||
|
||||
s, err := storage.CreateWALStore(filepath.Join(t.TempDir(), "r2.wal"), 64, 4096)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = s.Close() })
|
||||
l, err := transport.NewReplicaListener(addr, s)
|
||||
if err != nil {
|
||||
t.Skipf("could not re-bind %s: %v", addr, err)
|
||||
}
|
||||
l.Serve()
|
||||
t.Cleanup(func() { l.Stop() })
|
||||
deadline := time.Now().Add(10 * time.Second)
|
||||
for v.AttestedStores()["r2"] != s.StoreID() {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("the replica restarted, but the learner kept a broken connection (attested %v)", v.AttestedStores())
|
||||
}
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
@@ -553,11 +553,19 @@ func (e *BlockExecutor) Barrier(replicaID string, lineage RecoveryLineage, front
|
||||
|
||||
// Send request + receive response with deadlines on both sides
|
||||
// (sendBarrierReq / recvBarrierResp already set conn deadline).
|
||||
// A send or receive failure leaves the connection unusable: detach and
|
||||
// close it so the next barrier on this session re-dials (a caller that
|
||||
// does not invalidate the session, such as the store learner, would
|
||||
// otherwise reuse the dead socket forever).
|
||||
if err := sendBarrierReq(conn, lineage, recoveryConnTimeout); err != nil {
|
||||
e.detachConn(session, conn)
|
||||
_ = conn.Close()
|
||||
return BarrierAck{}, fmt.Errorf("transport: barrier: send replica=%s: %w", replicaID, err)
|
||||
}
|
||||
resp, err := recvBarrierResp(conn, recoveryConnTimeout)
|
||||
if err != nil {
|
||||
e.detachConn(session, conn)
|
||||
_ = conn.Close()
|
||||
return BarrierAck{}, fmt.Errorf("transport: barrier: recv replica=%s: %w", replicaID, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user