Skip to content

Commit d5cfa20

Browse files
committed
fix(redis-adapter): resolve timeout when fetching sockets from empty rooms
When calling FetchSockets or AllRooms with Redis adapter in a multi-server setup, if a room doesn't exist or has no connections on some servers, those servers return empty arrays. Due to the omitempty JSON tag, the response field becomes nil after deserialization. Previously, the code would return early when response.Sockets or response.Rooms was nil, but MsgCount had already been incremented. This caused the completion check (MsgCount == NumSub) to never execute, resulting in the request timing out instead of resolving. Changed nil checks to len() > 0 checks so that empty responses still proceed to the completion check, allowing the callback to trigger correctly. Closes #111
1 parent 9d65838 commit d5cfa20

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

adapters/redis/adapter/redis-adapter.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,9 @@ func (r *redisAdapter) processResponse(request *RedisRequest, response *Response
619619
case redis.SOCKETS, redis.REMOTE_FETCH:
620620
request.MsgCount.Add(1)
621621

622-
if response.Sockets == nil {
623-
return
622+
if len(response.Sockets) > 0 {
623+
request.Sockets.Push(response.Sockets...)
624624
}
625-
request.Sockets.Push(response.Sockets...)
626625

627626
if request.MsgCount.Load() == request.NumSub {
628627
utils.ClearTimeout(request.Timeout.Load())
@@ -637,10 +636,9 @@ func (r *redisAdapter) processResponse(request *RedisRequest, response *Response
637636
case redis.ALL_ROOMS:
638637
request.MsgCount.Add(1)
639638

640-
if response.Rooms == nil {
641-
return
639+
if len(response.Rooms) > 0 {
640+
request.Rooms.Add(response.Rooms...)
642641
}
643-
request.Rooms.Add(response.Rooms...)
644642

645643
if request.MsgCount.Load() == request.NumSub {
646644
utils.ClearTimeout(request.Timeout.Load())

0 commit comments

Comments
 (0)