[GH-ISSUE #1022] Failed to close redis client connection: redis connection is shared so the Client can't be closed through asynq #2513

Closed
opened 2026-03-15 20:45:17 +03:00 by kerem · 2 comments
Owner

Originally created by @MadanaGopalD on GitHub (Feb 13, 2025).
Original GitHub issue: https://github.com/hibiken/asynq/issues/1022

Originally assigned to: @hibiken, @kamikazechaser on GitHub.

Describe the bug
A clear and concise description of what the bug is.

Environment (please complete the following information):

  • OS: Linux
  • asynq package version [e.g. v0.25.1]
  • Redis/Valkey version

To Reproduce
Steps to reproduce the behavior (Code snippets if applicable):

func NewRedisClient(dataCfg *conf.Data, logger log.Logger) (redis.UniversalClient, func()) {
// log := log.NewHelper(logger)
var addrs = []string{dataCfg.Redis.Addr}
rdb := redis.NewUniversalClient(&redis.UniversalOptions{Addrs: addrs,
Password: dataCfg.Redis.Password,
WriteTimeout: dataCfg.Redis.WriteTimeout.AsDuration(),
ReadTimeout: dataCfg.Redis.ReadTimeout.AsDuration()})
return rdb, func() {
log.Info("closing redis connection")
if err := rdb.Close(); err != nil {
log.Error("error in closing redis client ", err)
}
}
}

func NewAsynqClientConn(redis redis.UniversalClient) *asynq.Client {
asynqClient := asynq.NewClientFromRedisClient(redis)
return asynqClient
}

I have created AsynqClient, AsynqServer and PeriodicTaskManager in my application, but while closing the application I am getting the following error
asynq: pid=53613 2025/02/13 10:14:23.071065 ERROR: Failed to close redis client connection: redis connection is shared so the Client can't be closed through asynq
Can someone explain me what's causing this error.

Originally created by @MadanaGopalD on GitHub (Feb 13, 2025). Original GitHub issue: https://github.com/hibiken/asynq/issues/1022 Originally assigned to: @hibiken, @kamikazechaser on GitHub. **Describe the bug** A clear and concise description of what the bug is. **Environment (please complete the following information):** - OS: Linux - `asynq` package version [e.g. v0.25.1] - Redis/Valkey version **To Reproduce** Steps to reproduce the behavior (Code snippets if applicable): func NewRedisClient(dataCfg *conf.Data, logger log.Logger) (redis.UniversalClient, func()) { // log := log.NewHelper(logger) var addrs = []string{dataCfg.Redis.Addr} rdb := redis.NewUniversalClient(&redis.UniversalOptions{Addrs: addrs, Password: dataCfg.Redis.Password, WriteTimeout: dataCfg.Redis.WriteTimeout.AsDuration(), ReadTimeout: dataCfg.Redis.ReadTimeout.AsDuration()}) return rdb, func() { log.Info("closing redis connection") if err := rdb.Close(); err != nil { log.Error("error in closing redis client ", err) } } } func NewAsynqClientConn(redis redis.UniversalClient) *asynq.Client { asynqClient := asynq.NewClientFromRedisClient(redis) return asynqClient } I have created AsynqClient, AsynqServer and PeriodicTaskManager in my application, but while closing the application I am getting the following error asynq: pid=53613 2025/02/13 10:14:23.071065 ERROR: Failed to close redis client connection: redis connection is shared so the Client can't be closed through asynq Can someone explain me what's causing this error.
kerem 2026-03-15 20:45:17 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@Harvi-C commented on GitHub (Mar 27, 2025):

你应该看一下它的源码实现,当你基于 redis 实例初始化 asynq 时,sharedConnection 会被设置为 True,如果你试图关闭它,它就会报错,这是设计如此,你可以忽略,因为 client 本身就只是被 redis 委托做了一些入队的操作而已

Image Image
<!-- gh-comment-id:2757980378 --> @Harvi-C commented on GitHub (Mar 27, 2025): 你应该看一下它的源码实现,当你基于 redis 实例初始化 asynq 时,sharedConnection 会被设置为 True,如果你试图关闭它,它就会报错,这是设计如此,你可以忽略,因为 client 本身就只是被 redis 委托做了一些入队的操作而已 <img width="630" alt="Image" src="https://github.com/user-attachments/assets/d4cd2332-0770-446b-a1e8-0baa3f67bca5" /> <img width="739" alt="Image" src="https://github.com/user-attachments/assets/4df11f53-eaf9-4b8b-a02f-e5cfd02f5a47" />
Author
Owner

@kamikazechaser commented on GitHub (May 15, 2025):

Call Close on your redis client instead of through asynq. The screenshots describe it above.

<!-- gh-comment-id:2882791308 --> @kamikazechaser commented on GitHub (May 15, 2025): Call Close on your redis client instead of through asynq. The screenshots describe it above.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#2513
No description provided.