Skip to content
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

example/gui-linux does not exit when vm.Stop() is used #150

Open
cfergeau opened this issue Nov 10, 2023 · 0 comments · May be fixed by #154
Open

example/gui-linux does not exit when vm.Stop() is used #150

cfergeau opened this issue Nov 10, 2023 · 0 comments · May be fixed by #154
Labels
bug Something isn't working

Comments

@cfergeau
Copy link
Contributor

cfergeau commented Nov 10, 2023

Describe the bug
The GUI code in virtualization_view.m is notified when there was a guest initiated shutdown ('guestDidStopVirtualMachine') and when there was a virtualization error ('didStopWithError').

When calling Stop(), the VM is forcefully stopped (similar to pulling the plug on real hardware). This action is neither a guest initiated shutdown, nor a virtualization error, so the GUI code does not catch it. This means after calling vm.Stop(), the GUI main loop will keep running, and the application using Code-Hex/vz will never exit.

The branch https://github.com/cfergeau/vz/tree/hardstop-gui has a fix for this bug. It adds an observer for VM state changes, and calls 'terminate' when the VM state becomes 'stopped' or 'error'.

I can file a PR if this approach is acceptable to you, or I can explore a different fix if needed.

This was initially reported as crc-org/vfkit#67

To Reproduce
Steps to reproduce the behavior:

  1. Apply this patch
diff --git a/example/gui-linux/main.go b/example/gui-linux/main.go
index 5db3f99..b98bdd7 100644
--- a/example/gui-linux/main.go
+++ b/example/gui-linux/main.go
@@ -77,6 +77,17 @@ func run(ctx context.Context) error {
                }
        }()
 
+       go func() {
+               if !vm.CanStop() {
+                       log.Println("cannot stop vm forcefully")
+                       return
+               }
+               time.Sleep(10 * time.Second)
+               log.Println("calling vm.Stop()")
+
+               vm.Stop()
+       }()
+
        // cleanup is this function is useful when finished graphic application.
        cleanup := func() {
                for i := 1; vm.CanRequestStop(); i++ {

(this change is made in my branch https://github.com/cfergeau/vz/tree/hardstop-gui)

  1. Start gui-linux

Expected behavior

The process stops after 10 seconds.

Environment that you use to compile (please complete the following information):

  • macOS Version: [sw_vers | pbcopy]
ProductVersion:		13.6.1
BuildVersion:		22G313
  • mac architecture: [uname -m | pbcopy] arm64
  • Go Version: [go version | pbcopy] go version go1.20.5 darwin/arm64
@cfergeau cfergeau added the bug Something isn't working label Nov 10, 2023
cfergeau added a commit to cfergeau/vz that referenced this issue Nov 10, 2023
The GUI code in virtualization_view.m is notified when there was a guest
initiated shutdown ('guestDidStopVirtualMachine') and when there was a
virtualization error ('didStopWithError').

When calling Stop(), the VM is forcefully stopped (similar to pulling
the plug on real hardware). This action is neither a guest initiated
shutdown, nor a virtualization error, so the GUI code does not catch
it. This means after calling vm.Stop(), the GUI main loop will keep
running, and the application using Code-Hex/vz will never exit.

This commit fixes this by adding an observer for VM state changes, and
by calling 'terminate' when the VM state becomes 'stopped' or 'error'.

This fixes Code-Hex#150
cfergeau added a commit to cfergeau/vz that referenced this issue Jan 23, 2024
The GUI code in virtualization_view.m is notified when there was a guest
initiated shutdown ('guestDidStopVirtualMachine') and when there was a
virtualization error ('didStopWithError').

When calling Stop(), the VM is forcefully stopped (similar to pulling
the plug on real hardware). This action is neither a guest initiated
shutdown, nor a virtualization error, so the GUI code does not catch
it. This means after calling vm.Stop(), the GUI main loop will keep
running, and the application using Code-Hex/vz will never exit.

This commit fixes this by adding an observer for VM state changes, and
by calling 'terminate' when the VM state becomes 'stopped' or 'error'.

This fixes Code-Hex#150
@cfergeau cfergeau linked a pull request Jan 23, 2024 that will close this issue
cfergeau added a commit to cfergeau/vz that referenced this issue Mar 29, 2024
The GUI code in virtualization_view.m is notified when there was a guest
initiated shutdown ('guestDidStopVirtualMachine') and when there was a
virtualization error ('didStopWithError').

When calling Stop(), the VM is forcefully stopped (similar to pulling
the plug on real hardware). This action is neither a guest initiated
shutdown, nor a virtualization error, so the GUI code does not catch
it. This means after calling vm.Stop(), the GUI main loop will keep
running, and the application using Code-Hex/vz will never exit.

This commit fixes this by adding an observer for VM state changes, and
by calling 'terminate' when the VM state becomes 'stopped' or 'error'.

This fixes Code-Hex#150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant