mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-25 23:15:51 +03:00
[GH-ISSUE #979] [BUG] asynq:servers and asynq:workers not cleaned after shutdown #1484
Labels
No labels
CLI
bug
designing
documentation
duplicate
enhancement
good first issue
good first issue
help wanted
idea
invalid
investigate
needs-more-info
performance
pr-welcome
pull-request
question
wontfix
work in progress
work in progress
work-around-available
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/asynq#1484
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Skwol on GitHub (Dec 6, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/979
Originally assigned to: @hibiken, @kamikazechaser on GitHub.
Describe the bug
redis
asynq:serversandasynq:workerssets are note being cleaned up during server shutdown.Environment (please complete the following information):
asynqpackage version v0.25.0To Reproduce
Perform same actions but add time.Sleep(2*time.Second) after server.Shutdown() and you can see that closed workers/servers cleaned up.
Dockerfile:
docker-compose.yaml:
main.go:
Expected behavior
redis sets
asynq:serversandasynq:workersshould not contain old servers/workersAdditional context
In some infrastructure where we might have a lot of workers these sets become huge during active development. Not sure when it will affect performance or cause any troubles.
@Skwol commented on GitHub (Dec 6, 2024):
As I understand the issue lies somewhere in the lock of the server.Shutdown(). In my code I call server.Run() and server.Shutdown(). And server.Run() actually already have signals waiting and Shutdown(). When I remove server.Shutdown() from a client code everything runs smoothly and clean up happens.
Ideally need to handle this case properly (lock) or remove shutdown from the public api.
@kamikazechaser commented on GitHub (Dec 7, 2024):
Server.Run internally registers SIGINT listeners. Could you use Server.Start instead because you are registering your own listeners.
Also, could you try with v0.24.1 and see if it is reproducible.
@Skwol commented on GitHub (Dec 7, 2024):
Tried the same with v0.24.1 and the result is the same. It requires use some delay/sleep to clean up.
You're 100% sure, I need to use Start + Shutdown or Run. It works for me and I'll be fine, but it looks like it better to have this case (case when user tries Run+Shutdown) restricted/handled somehow.
Anyway, thank you for the response.
@kamikazechaser commented on GitHub (Dec 9, 2024):
I managed to reproduce it. It is in fact a bug. If the server state is never set with Stop the entire shutdown procedure is skipped. On Unix it is never stopped unless SIGSTP is called.
https://github.com/hibiken/asynq/blob/master/signals_unix.go#L25
The 2 second that you add allows the Stop to actually set the correct state which further allows the seconds explicit shutdown to complete before the goroutine can return.
I'll push some code that you can try out.
@kamikazechaser commented on GitHub (Dec 9, 2024):
@Skwol Could you try:
@Skwol commented on GitHub (Dec 9, 2024):
I updated my code. The cleanup worked fine with this version. Thank you, hope to see it in the new release!