fix: stop writes to closed cluster sessions

This commit is contained in:
richjohnrambo
2026-10-02 00:28:02 +08:00
parent d43b1b63d3
commit a406d63154
3 changed files with 98 additions and 0 deletions
+29
View File
@@ -4,6 +4,7 @@ import (
"net"
"net/rpc"
"sync"
"sync/atomic"
"testing"
"time"
@@ -83,3 +84,31 @@ func TestClusterWriteLoopPreservesTopicOrder(t *testing.T) {
t.Fatalf("cluster responses arrived out of order: %v", proxy.received)
}
}
func TestClusterWriteLoopRejectsWritesAfterTermination(t *testing.T) {
previousSessionStore := globals.sessionStore
globals.sessionStore = NewSessionStore(time.Minute)
t.Cleanup(func() { globals.sessionStore = previousSessionStore })
sess := &Session{
sid: "multiplex-termination-test",
proto: MULTIPLEX,
send: make(chan any, 1),
stop: make(chan any, 1),
detach: make(chan string, 1),
subs: make(map[string]*Subscription),
}
sess.stop <- nil
sess.clusterWriteLoop("grp-termination-test")
if atomic.LoadInt32(&sess.terminating) == 0 {
t.Fatal("terminated multiplexing session still accepts writes")
}
if !sess.queueOut(&ServerComMessage{TenantID: types.TenantID(1)}) {
t.Fatal("write to terminated multiplexing session should be discarded")
}
if len(sess.send) != 0 {
t.Fatalf("terminated multiplexing session retained %d outbound messages", len(sess.send))
}
}