From 1ac6a259dd5f16bfcb40622fc3d281398a0690d6 Mon Sep 17 00:00:00 2001 From: buvidk1234 <161066602+buvidk1234@users.noreply.github.com> Date: Thu, 4 Jun 2026 20:03:52 +0800 Subject: [PATCH] Modify conversation_id index options (#3722) * Modify conversation_id index options Removed the unique constraint from the conversation_id index. * fix(msggateway): reset read deadline in pong handler to prevent Web client timeout Root cause: Due to browser API restrictions, Web (Wasm) clients cannot actively send standard WebSocket Ping frames. They rely entirely on server-initiated Pings (every 27s) and automatic browser Pong responses to maintain the connection. The `pongHandler` was empty and failed to reset the connection's read deadline upon receiving a Pong, causing the server's read loop to strictly time out at 30 seconds. Solution: Call `c.setReadDeadline()` inside the `pongHandler` to properly extend the connection's lifespan when a Pong frame is received. --------- Co-authored-by: OpenIM-Gordon <1432970085@qq.com> --- internal/msggateway/client_conn.go | 6 +++++- pkg/common/storage/database/mgo/conversation.go | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/msggateway/client_conn.go b/internal/msggateway/client_conn.go index 15a0d8c07..0fb1620a6 100644 --- a/internal/msggateway/client_conn.go +++ b/internal/msggateway/client_conn.go @@ -208,7 +208,11 @@ func (c *websocketClientConn) pingHandler(appData string) error { return nil } -func (c *websocketClientConn) pongHandler(string) error { +func (c *websocketClientConn) pongHandler(appData string) error { + log.ZDebug(context.Background(), "pong handler recv pong", "remoteAddr", c.conn.RemoteAddr(), "appData", appData) + if err := c.setReadDeadline(); err != nil { + return err + } return nil } diff --git a/pkg/common/storage/database/mgo/conversation.go b/pkg/common/storage/database/mgo/conversation.go index 2f9c063cc..30f08f5e5 100644 --- a/pkg/common/storage/database/mgo/conversation.go +++ b/pkg/common/storage/database/mgo/conversation.go @@ -47,6 +47,12 @@ func NewConversationMongo(db *mongo.Database) (*ConversationMgo, error) { }, Options: options.Index(), }, + { + Keys: bson.D{ + {Key: "conversation_id", Value: 1}, + }, + Options: options.Index(), + }, }) if err != nil { return nil, errs.Wrap(err)