[GH-ISSUE #975] [BUG] RedisClient created by PeriodicTaskManager doesn't close connection #2496

Closed
opened 2026-03-15 20:41:34 +03:00 by kerem · 4 comments
Owner

Originally created by @HuangShaoyan on GitHub (Nov 27, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/975

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

Describe the bug
asynq creates a scheduler using NewScheduler when invoking NewPeriodicTaskManager, setting scheduler.sharedConnection to false. However, scheduler.client.sharedConnection remains true.
It will cause Client.Close to print redis connection is shared so the Client can't be closed through asynq.

Environment:

  • OS: MacOS
  • asynq v0.25.0
  • Redis 7.0

To Reproduce

  1. Create a PeriodicTaskManager using asynq.NewPeriodicTaskManager.
  2. Press Ctrl+C to stop the process.
  3. Check the log output.

Expected behavior
asynq should set scheduler.client.sharedConnection to false when the Redis client is created by the PeriodicTaskManager itself.

Originally created by @HuangShaoyan on GitHub (Nov 27, 2024). Original GitHub issue: https://github.com/hibiken/asynq/issues/975 Originally assigned to: @hibiken, @kamikazechaser on GitHub. **Describe the bug** asynq creates a scheduler using `NewScheduler` when invoking `NewPeriodicTaskManager`, setting `scheduler.sharedConnection` to false. However, `scheduler.client.sharedConnection` remains true. It will cause `Client.Close` to print `redis connection is shared so the Client can't be closed through asynq`. **Environment:** - OS: MacOS - `asynq` v0.25.0 - Redis 7.0 **To Reproduce** 1. Create a PeriodicTaskManager using `asynq.NewPeriodicTaskManager`. 2. Press Ctrl+C to stop the process. 3. Check the log output. **Expected behavior** asynq should set `scheduler.client.sharedConnection` to `false` when the Redis client is created by the PeriodicTaskManager itself.
kerem 2026-03-15 20:41:34 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kamikazechaser commented on GitHub (Dec 3, 2024):

Probably landed in #958. Pinging @daixijun as well.

Actually landed in #742. I'll review the entire PR again.

<!-- gh-comment-id:2513610727 --> @kamikazechaser commented on GitHub (Dec 3, 2024): ~~Probably landed in #958. Pinging @daixijun as well.~~ Actually landed in #742. I'll review the entire PR again.
Author
Owner

@kamikazechaser commented on GitHub (Dec 3, 2024):

I can reproduce it:

asynq: pid=20593 2024/12/03 05:57:22.303908 INFO: Scheduler starting
asynq: pid=20593 2024/12/03 05:57:22.303939 INFO: Scheduler timezone is set to UTC
asynq: pid=20593 2024/12/03 05:57:22.303945 INFO: Send signal TERM or INT to stop the scheduler
^Casynq: pid=20593 2024/12/03 05:57:22.781738 INFO: Scheduler shutting down
asynq: pid=20593 2024/12/03 05:57:22.783083 ERROR: Failed to close redis client connection: redis connection is shared so the Client can't be closed through asynq
asynq: pid=20593 2024/12/03 05:57:22.783122 INFO: Scheduler stopped
2024/12/03 08:57:42 graceful shutdown period exceeded, forcefully shutting down
exit status 1
<!-- gh-comment-id:2513629305 --> @kamikazechaser commented on GitHub (Dec 3, 2024): I can reproduce it: ```bash asynq: pid=20593 2024/12/03 05:57:22.303908 INFO: Scheduler starting asynq: pid=20593 2024/12/03 05:57:22.303939 INFO: Scheduler timezone is set to UTC asynq: pid=20593 2024/12/03 05:57:22.303945 INFO: Send signal TERM or INT to stop the scheduler ^Casynq: pid=20593 2024/12/03 05:57:22.781738 INFO: Scheduler shutting down asynq: pid=20593 2024/12/03 05:57:22.783083 ERROR: Failed to close redis client connection: redis connection is shared so the Client can't be closed through asynq asynq: pid=20593 2024/12/03 05:57:22.783122 INFO: Scheduler stopped 2024/12/03 08:57:42 graceful shutdown period exceeded, forcefully shutting down exit status 1 ```
Author
Owner

@kamikazechaser commented on GitHub (Dec 3, 2024):

@HuangShaoyan I have pushed a fix pending review. Could you try it out? https://github.com/hibiken/asynq/tree/sohail/pm-redis-conn-hotfix

go get github.com/hibiken/asynq@f1e7dc4056abaa6549bf014d2e6b67508437d236

<!-- gh-comment-id:2513779016 --> @kamikazechaser commented on GitHub (Dec 3, 2024): @HuangShaoyan I have pushed a fix pending review. Could you try it out? https://github.com/hibiken/asynq/tree/sohail/pm-redis-conn-hotfix ` go get github.com/hibiken/asynq@f1e7dc4056abaa6549bf014d2e6b67508437d236`
Author
Owner

@HuangShaoyan commented on GitHub (Dec 3, 2024):

I have tested the fix f1e7dc, and I can confirm that the bug has been resolved.

<!-- gh-comment-id:2514789310 --> @HuangShaoyan commented on GitHub (Dec 3, 2024): I have tested the fix `f1e7dc`, and I can confirm that the bug has been resolved.
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#2496
No description provided.