From 60d0c192564941df2cf263f8097afd1e0f430833 Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 26 Oct 2023 16:42:17 +0900 Subject: [PATCH] =?UTF-8?q?redis=20=EC=A0=91=EC=86=8D=20=EC=8B=A4=ED=8C=A8?= =?UTF-8?q?=EC=8B=9C=20=EB=A1=9C=EA=B7=B8=EA=B0=80=20=EA=B3=BC=EB=8F=84?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EB=82=A8=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wshandler/wshandler.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wshandler/wshandler.go b/wshandler/wshandler.go index 01f8713..6533878 100644 --- a/wshandler/wshandler.go +++ b/wshandler/wshandler.go @@ -13,6 +13,7 @@ import ( "net/http" "strings" "sync" + "time" "go.mongodb.org/mongo-driver/bson/primitive" "repositories.action2quare.com/ayo/gocommon" @@ -211,6 +212,8 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) { // redis channel에서 유저가 보낸 메시지를 읽는 go rountine go func() { var pubsub *redis.PubSub + waittimer := time.Second + for { if pubsub == nil { pubsub = ws.redisSync.Subscribe(ctx, ws.redisMsgChanName, ws.redisCmdChanName) @@ -218,6 +221,8 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) { raw, err := pubsub.ReceiveMessage(ctx) if err == nil { + waittimer = time.Second + buffer := bytes.NewBuffer([]byte(raw.Payload)) dec := gob.NewDecoder(buffer) @@ -241,6 +246,12 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) { pubsub.Close() pubsub = nil + time.Sleep(waittimer) + waittimer = waittimer * 2 + if waittimer > time.Minute { + waittimer = time.Minute + } + if ctx.Err() != nil { break }