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
Fix CLI output hang after exceptions raised in spinners #2906
Conversation
Do we have an issue for |
Looks like kontena/kontena-plugin-shell#31, fixed in kontena/kontena-plugin-shell#33 for each separate |
@@ -168,6 +168,7 @@ def self.spin(msg, &block) | |||
Kernel.puts msg | |||
end | |||
end | |||
Thread.main['spinners'].delete(spin_thread) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we delete
the spin_thread
from Thread.main['spinners']
here in the ensure, then what does the Thread.main['spinners'].pop
later on after the ensure
block do... because if nothing gets raised, then this will run both the Thread.main['spinners'].delete(spin_thread)
and Thread.main['spinners'].pop
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it does both... the pop
is a no-op if the Thread.main['spinners']
is empty:
[done] Triggering deployment of stack stop-signal
delete #<Thread:0x000000021da7c0@/home/kontena/kontena/kontena/cli/lib/kontena/cli/spinner.rb:96 dead> from Thread.main['spinners']: [#<Thread:0x000000021da7c0@/home/kontena/kontena/kontena/cli/lib/kontena/cli/spinner.rb:96 dead>]
pop from Thread.main['spinners']: []
I'm guessing this would only be relevant for nested spinners, though... where in the CLI are those actually used? I couldn't find any with a quick look around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully not anywhere. There was one in the master deploy wizard but I think it has been removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this code be simplified to not be broken in complex cases that are not actually used? :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole spinner.rb should be buried. Very deep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno how the nested spinners are supposed to work, but testing by changing the kontena stack install
-> Installing dependency ...
into a spinner, it actually behaves alright with this buggy change, at least without errors:
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo .. \
[done] Creating stack deptest-foo
[done] Triggering deployment of stack deptest-foo
[done] Waiting for deployment to start
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar .. \
[done] Creating stack deptest-bar
[done] Triggering deployment of stack deptest-bar
[done] Waiting for deployment to start
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Creating stack deptest
[done] Triggering deployment of stack deptest
[done] Waiting for deployment to start
[done] Deploying service redis
In fact, I maybe like the "broken" output with the delete+pop in this PR more than the "working" output before this PR?
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo .. \
[done] Creating stack deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[done] Triggering deployment of stack deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[done] Waiting for deployment to start
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo .. |
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar .. \
[done] Creating stack deptest-bar
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Triggering deployment of stack deptest-bar
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Waiting for deployment to start
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar .. \
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Creating stack deptest
[done] Triggering deployment of stack deptest
[done] Waiting for deployment to start
[done] Deploying service redis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose I'll take working puts
in rescue
from spinner do ...
exceptions over "working" spinner nesting.
@@ -168,6 +168,7 @@ def self.spin(msg, &block) | |||
Kernel.puts msg | |||
end | |||
end | |||
Thread.main['spinners'].delete(spin_thread) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -168,6 +168,7 @@ def self.spin(msg, &block) | |||
Kernel.puts msg | |||
end | |||
end | |||
Thread.main['spinners'].delete(spin_thread) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno how the nested spinners are supposed to work, but testing by changing the kontena stack install
-> Installing dependency ...
into a spinner, it actually behaves alright with this buggy change, at least without errors:
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo .. \
[done] Creating stack deptest-foo
[done] Triggering deployment of stack deptest-foo
[done] Waiting for deployment to start
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar .. \
[done] Creating stack deptest-bar
[done] Triggering deployment of stack deptest-bar
[done] Waiting for deployment to start
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Creating stack deptest
[done] Triggering deployment of stack deptest
[done] Waiting for deployment to start
[done] Deploying service redis
In fact, I maybe like the "broken" output with the delete+pop in this PR more than the "working" output before this PR?
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo .. \
[done] Creating stack deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[done] Triggering deployment of stack deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[done] Waiting for deployment to start
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo .. |
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-foo
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar .. \
[done] Creating stack deptest-bar
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Triggering deployment of stack deptest-bar
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Waiting for deployment to start
[....] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar .. \
[done] Deploying service redis
[done] Installing dependency /home/kontena/kontena/kontena/cli/test/deptest-child.yaml as deptest-bar
[done] Creating stack deptest
[done] Triggering deployment of stack deptest
[done] Waiting for deployment to start
[done] Deploying service redis
Spinners may leave behind their spinner-threads making
Kontena::Cli::Common#puts
eat all the messages.Normally this does not matter because usually the command exits and nobody notices. But when running through
Kontena.run!
or the way KOSH does it, the threads are left behind and prevent any furtherputs
ing.As a sidenote, the selfmade spinner implementation is far from excellent and should probably be replaced with something like
tty-spinner