[GH-ISSUE #993] [FEATURE REQUEST] I hope the Scheduler can allow me to manually close connections when using shared connections, just like Server does. #1490

Open
opened 2026-03-07 22:10:00 +03:00 by kerem · 5 comments
Owner

Originally created by @PterX on GitHub (Dec 21, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/993

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

Is your feature request related to a problem? Please describe.
[A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]](asynq: pid=40565 2024/12/21 13:38:01.521847 ERROR: Failed to close redis client connection: redis connection is shared so the Client can't be closed through asynq)

Describe the solution you'd like

func (srv *Server) Shutdown() {
	srv.state.mu.Lock()
	if srv.state.value == srvStateNew || srv.state.value == srvStateClosed {
		srv.state.mu.Unlock()
		// server is not running, do nothing and return.
		return
	}
	...
	srv.wg.Wait()

	if !srv.sharedConnection {
		srv.broker.Close()
	}
func (s *Scheduler) Shutdown() {
	s.state.mu.Lock()
	....
	s.wg.Wait()

	s.clearHistory()
        // if sharedConnection did not close it
	if err := s.client.Close(); err != nil {
		s.logger.Errorf("Failed to close redis client connection: %v", err)
	}
	s.logger.Info("Scheduler stopped")
}

It can close redis connect after that

Describe alternatives you've considered

Additional context

Originally created by @PterX on GitHub (Dec 21, 2024). Original GitHub issue: https://github.com/hibiken/asynq/issues/993 Originally assigned to: @hibiken, @kamikazechaser on GitHub. **Is your feature request related to a problem? Please describe.** [A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]](asynq: pid=40565 2024/12/21 13:38:01.521847 ERROR: Failed to close redis client connection: redis connection is shared so the Client can't be closed through asynq) **Describe the solution you'd like** ``` func (srv *Server) Shutdown() { srv.state.mu.Lock() if srv.state.value == srvStateNew || srv.state.value == srvStateClosed { srv.state.mu.Unlock() // server is not running, do nothing and return. return } ... srv.wg.Wait() if !srv.sharedConnection { srv.broker.Close() } ``` ``` func (s *Scheduler) Shutdown() { s.state.mu.Lock() .... s.wg.Wait() s.clearHistory() // if sharedConnection did not close it if err := s.client.Close(); err != nil { s.logger.Errorf("Failed to close redis client connection: %v", err) } s.logger.Info("Scheduler stopped") } ``` It can close redis connect after that **Describe alternatives you've considered** **Additional context**
Author
Owner

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

I'm always frustrated when...redis connection is shared so the Client can't be closed through asynq

I assume you are talking about the bug affecting the Scheduler (See #975)? Try v0.25.1 if so.

<!-- gh-comment-id:2558924123 --> @kamikazechaser commented on GitHub (Dec 23, 2024): > I'm always frustrated when...redis connection is shared so the Client can't be closed through asynq I assume you are talking about the bug affecting the Scheduler (See #975)? Try v0.25.1 if so.
Author
Owner

@PterX commented on GitHub (Dec 24, 2024):

I'm always frustrated when...redis connection is shared so the Client can't be closed through asynq

I assume you are talking about the bug affecting the Scheduler (See #975)? Try v0.25.1 if so.

I think is not the same, I was use NewSchedulerFromRedisClient create Scheduler, it is also shareconnection. But i want shutdown Scheduler before close share connection, It will post the error msg.

<!-- gh-comment-id:2560798903 --> @PterX commented on GitHub (Dec 24, 2024): > > I'm always frustrated when...redis connection is shared so the Client can't be closed through asynq > > I assume you are talking about the bug affecting the Scheduler (See #975)? Try v0.25.1 if so. I think is not the same, I was use NewSchedulerFromRedisClient create Scheduler, it is also shareconnection. But i want shutdown Scheduler before close share connection, It will post the error msg.
Author
Owner

@PterX commented on GitHub (Dec 25, 2024):

github.com/PterX/asynq@f8e132031d

@kamikazechaser maybe fix like this

<!-- gh-comment-id:2561756211 --> @PterX commented on GitHub (Dec 25, 2024): https://github.com/PterX/asynq/commit/f8e132031da984dfab771979d05566743a3e4143 @kamikazechaser maybe fix like this
Author
Owner

@MadanaGopalD commented on GitHub (Feb 14, 2025):

@PterX github.com/PterX/asynq@f8e132031d
I was going though the same issue and your fix worked well for me!
Will this be added to next release?

<!-- gh-comment-id:2658260719 --> @MadanaGopalD commented on GitHub (Feb 14, 2025): @PterX https://github.com/PterX/asynq/commit/f8e132031da984dfab771979d05566743a3e4143 I was going though the same issue and your fix worked well for me! Will this be added to next release?
Author
Owner

@PterX commented on GitHub (Feb 14, 2025):

@PterX PterX@f8e1320 I was going though the same issue and your fix worked well for me! Will this be added to next release?

Maybe you can help submit a PR

<!-- gh-comment-id:2658341295 --> @PterX commented on GitHub (Feb 14, 2025): > [@PterX](https://github.com/PterX) [PterX@f8e1320](https://github.com/PterX/asynq/commit/f8e132031da984dfab771979d05566743a3e4143) I was going though the same issue and your fix worked well for me! Will this be added to next release? Maybe you can help submit a PR
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#1490
No description provided.