From 1d2cb7c8055a5aa7687af782aede8331de282a19 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Mon, 11 Jul 2022 23:26:47 +0530 Subject: [PATCH] Fix incorrect dead queue clear logic (#20624) We were incorrectly returning from the method without resetting the pointer. Fixes https://github.com/mattermost/mattermost-server/issues/20622 ```release-note NONE ``` --- app/web_conn.go | 2 +- app/web_conn_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/web_conn.go b/app/web_conn.go index 5ac66c008e..bc260b49bc 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -580,7 +580,7 @@ func (wc *WebConn) isInDeadQueue(seq int64) (bool, int) { func (wc *WebConn) clearDeadQueue() { for i := 0; i < deadQueueSize; i++ { if wc.deadQueue[i] == nil { - return + break } wc.deadQueue[i] = nil } diff --git a/app/web_conn_test.go b/app/web_conn_test.go index be9dbdc56f..5fdcb29ee8 100644 --- a/app/web_conn_test.go +++ b/app/web_conn_test.go @@ -276,6 +276,26 @@ func TestWebConnIsInDeadQueue(t *testing.T) { assert.False(t, wc.hasMsgLoss()) } +func TestWebConnClearDeadQueue(t *testing.T) { + th := Setup(t) + defer th.TearDown() + + wc := th.App.NewWebConn(&WebConnConfig{ + WebSocket: &websocket.Conn{}, + }) + + var i int + for ; i < 2; i++ { + msg := &model.WebSocketEvent{} + msg = msg.SetSequence(int64(i)) + wc.addToDeadQueue(msg) + } + + wc.clearDeadQueue() + + assert.Equal(t, 0, wc.deadQueuePointer) +} + func TestWebConnDrainDeadQueue(t *testing.T) { th := Setup(t) defer th.TearDown()