fix: stop writes to closed cluster sessions
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user