-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes a bug that Ctrl-c not working on Salt CLI. #35923
Conversation
18e5c58
to
07e2575
Compare
@s0undt3ch Since you've been doing so much signals/shutdown work lately I would love to have your opinion here. |
07e2575
to
26d7275
Compare
I just found another issue on this issue, so I want to suggest another way to fix the stalling and memory leaking bug. First of all, check following toy example. the
So the this line will never be called after signal handlers are set. Especially, Salt Master process never call the |
26d7275
to
312e34a
Compare
312e34a
to
6569267
Compare
I'm fine with this change on the CLI tools but could you please clarify what's broken with the current salt-master implementation of signal handling? I'm not following why that needs to be changed as well. |
@cachedout Thank you for your review, and sure, I will explain about the issue of As I tested, the Because of the Python's control flow between |
This approach looks solid! Thanks @kstreee! |
Thanks for the explanation, @kstreee. I appreciate it. I agree that this looks like it's a solid approach. Let's go ahead and get this in. |
What does this PR do?
Fixes a bug that Ctrl-c not working on Salt CLI because of this line. There is no way to terminate Salt CLI when the exception
KeyboardInterrupt
is caught by the line. It could be a problem for all kind of modules that callget_event
directly.In Salt Master, the above line is not a problem because of
EventReturn
will handle the exit signal on the background thread, but Salt CLI tools can't because they do not use theEventReturn
. Also, it causes kind of memory leak that is caused by generatingfuture
object infinitely.We know our solution, which uses
graceful_exit
flag, is not a beautiful way to solve this, but we think it is quite intuitive. We considered attachingEventReturn
to Salt CLI processes, but we thought that the attaching solution is too much to solve this problem. If you have any other solution to resolve this issue, please let me know about it. I am open to discussion.We could not check all call sites for the function
get_event
, thus if this commit is reasonable to fix this issue and is accepted, then other call sites should be reviewed.F.Y.I. To minimize impacts of this commit, I set a default value of
graceful_exit
asTrue
.What issues does this PR fix or reference?
Previous Behavior
When users send a kill signal (for example, hitting Ctrl-c) while Salt CLI tools execute
get_event
, then the running Salt CLI process stalls and causes kind of memory leak.New Behavior
Exits immediately, even Salt CLI received a kill signal while executing
get_event
.Tests written?
No, I have no idea to make a test for Ctrl-c. If you have any examples or recommended way, I will gladly learn about it and make test cases.