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 }