Skip to content

ShowAndRun sometimes fails to return on Windows #6021

@antxv

Description

@antxv

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

I am building an application on Windows 11. About 1% of the time I attempt to close the is single window, window.ShowAndRun() does not return. I have included my main.go, but this relies on a lot of other code, so you will not be able to run it. I am using a custom layout and a custom raster-based widget. From the main code, you can see that I am using SetMaster(), and i am printing pprof routine information before and after the expected shut down to help debug. My custom code is only creating one extra background routine, which is confirmed in the output to be completed by Cleanup() ("finishing blink ticker").

When the application hangs like this, Windows Task Manager reports the application as a background process.

Here is the tail end of my application output:

gridTextRenderer.Cleanup()
gridTextRenderer.Cleanup()
gridTextRenderer.Cleanup()
--- Goroutine Profile Output (OnClosed) ---
goroutine 1 [running, locked to thread]:
runtime/pprof.writeGoroutineStacks({0x7ff641e6a600, 0xc000080068})
	C:/Program Files/Go/src/runtime/pprof/pprof.go:764 +0x6a
runtime/pprof.writeGoroutine({0x7ff641e6a600?, 0xc000080068?}, 0x26?)
	C:/Program Files/Go/src/runtime/pprof/pprof.go:753 +0x25
runtime/pprof.(*Profile).WriteTo(0x7ff641e6a600?, {0x7ff641e6a600?, 0xc000080068?}, 0x26?)
	C:/Program Files/Go/src/runtime/pprof/pprof.go:377 +0x14b
main.printDebug({0x7ff641d56a3f, 0x8})
	d:/go/utterlyeditor/main.go:29 +0xc5
main.main.func1()
	d:/go/utterlyeditor/main.go:67 +0x5d
fyne.io/fyne/v2/internal/driver/glfw.(*window).processClosed.(*window).Close.func1()
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window.go:200 +0x66
fyne.io/fyne/v2/internal/async.EnsureMain(0xc0001d9590)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/goroutine.go:46 +0x3f
fyne.io/fyne/v2/internal/driver/glfw.(*window).Close(...)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window.go:192
fyne.io/fyne/v2/internal/driver/glfw.(*window).processClosed(0xc00029c9c0)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window.go:247 +0x5c
fyne.io/fyne/v2/internal/driver/glfw.(*window).closed(0xc00029c9c0?, 0xc000045a60?)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window_desktop.go:365 +0x2f
github.com/go-gl/glfw/v3.3/glfw.goWindowCloseCB(0x400000001?)
	C:/Users/MY_USERNAME/go/pkg/mod/github.com/go-gl/glfw/v3.3/[email protected]/window.go:224 +0x26
github.com/go-gl/glfw/v3.3/glfw._Cfunc_glfwPollEvents()
	_cgo_gotypes.go:1544 +0x45
github.com/go-gl/glfw/v3.3/glfw.PollEvents()
	C:/Users/MY_USERNAME/go/pkg/mod/github.com/go-gl/glfw/v3.3/[email protected]/window.go:931 +0x13
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).pollEvents(...)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop_desktop.go:22
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).runGL(0x7ff640cfce37?)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:154 +0x1aa
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).Run(0xc0002ec840)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver.go:162 +0x72
fyne.io/fyne/v2/app.(*fyneApp).Run(0xc0002ec8f0)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/app/app.go:77 +0x102
fyne.io/fyne/v2/internal/driver/glfw.(*window).ShowAndRun(0xc00029c9c0)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window.go:217 +0x64
main.main()
	d:/go/utterlyeditor/main.go:89 +0x418

goroutine 7 [select]:
fyne.io/fyne/v2/internal/async.(*UnboundedChan[...]).processing(0x7ff641e79900)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/chan.go:43 +0xdc
created by fyne.io/fyne/v2/internal/async.NewUnboundedChan[...] in goroutine 1
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/chan.go:20 +0x10a

goroutine 8 [select]:
fyne.io/fyne/v2/internal/async.(*UnboundedChan[...]).processing(0x7ff641e79860)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/chan.go:43 +0xdf
created by fyne.io/fyne/v2/internal/async.NewUnboundedChan[...] in goroutine 1
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/chan.go:20 +0x10a

goroutine 39 [runnable]:
utterlyeditor/gridtext.(*gridTextRenderer).Focus.func1()
	d:/go/utterlyeditor/gridtext/grid_text_renderer.go:182 +0x105
created by utterlyeditor/gridtext.(*gridTextRenderer).Focus in goroutine 1
	d:/go/utterlyeditor/gridtext/grid_text_renderer.go:177 +0x76

goroutine 15 [chan receive]:
fyne.io/fyne/v2/internal/app.(*Lifecycle).RunEventQueue(...)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/app/lifecycle.go:110
created by fyne.io/fyne/v2/app.(*fyneApp).Run in goroutine 1
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/app/app.go:71 +0xbe

goroutine 23 [chan receive]:
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).catchTerm(0xc0002ec840)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver_desktop.go:210 +0x74
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).Run in goroutine 1
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver.go:161 +0x68

goroutine 50 [syscall]:
os/signal.signal_recv()
	C:/Program Files/Go/src/runtime/sigqueue.go:152 +0x29
os/signal.loop()
	C:/Program Files/Go/src/os/signal/signal_unix.go:23 +0x13
created by os/signal.Notify.func1.1 in goroutine 23
	C:/Program Files/Go/src/os/signal/signal.go:152 +0x1f
--- End of Profile Output ---
gridTextRenderer.Destroy()
gridTextRenderer.Destroy()
gridTextRenderer.Destroy()
finishing blink ticker
routines running: 7
routines running: 6
routines running: 6
routines running: 6
routines running: 6
--- Goroutine Profile Output (FAILED TO CLOSE) ---
goroutine 40 [running]:
runtime/pprof.writeGoroutineStacks({0x7ff641e6a600, 0xc000080068})
	C:/Program Files/Go/src/runtime/pprof/pprof.go:764 +0x6a
runtime/pprof.writeGoroutine({0x7ff641e6a600?, 0xc000080068?}, 0x26?)
	C:/Program Files/Go/src/runtime/pprof/pprof.go:753 +0x25
runtime/pprof.(*Profile).WriteTo(0x7ff641e6a600?, {0x7ff641e6a600?, 0xc000080068?}, 0x26?)
	C:/Program Files/Go/src/runtime/pprof/pprof.go:377 +0x14b
main.printDebug({0x7ff641d5f0ca, 0xf})
	d:/go/utterlyeditor/main.go:29 +0xc5
main.main.func1.1()
	d:/go/utterlyeditor/main.go:78 +0xf0
created by main.main.func1 in goroutine 1
	d:/go/utterlyeditor/main.go:68 +0x69

goroutine 1 [chan receive, locked to thread]:
fyne.io/fyne/v2/internal/app.(*Lifecycle).WaitForEvents(...)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/app/lifecycle.go:120
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).Run(0xc0002ec840)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver.go:166 +0x113
fyne.io/fyne/v2/app.(*fyneApp).Run(0xc0002ec8f0)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/app/app.go:77 +0x102
fyne.io/fyne/v2/internal/driver/glfw.(*window).ShowAndRun(0xc00029c9c0)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window.go:217 +0x64
main.main()
	d:/go/utterlyeditor/main.go:89 +0x418

goroutine 8 [select]:
fyne.io/fyne/v2/internal/async.(*UnboundedChan[...]).processing(0x7ff641e79860)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/chan.go:43 +0xdf
created by fyne.io/fyne/v2/internal/async.NewUnboundedChan[...] in goroutine 1
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/chan.go:20 +0x10a

goroutine 15 [chan receive]:
fyne.io/fyne/v2/internal/driver/glfw.runOnMainWithWait(0xc0002c76d0, 0x1)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:53 +0xfc
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).DoFromGoroutine.func1()
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver.go:70 +0x1c
fyne.io/fyne/v2/internal/async.EnsureNotMain(0xc0001d95b0)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/async/goroutine.go:29 +0x3f
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).DoFromGoroutine(0xc0001fe540?, 0xc0002c76d0, 0x1?)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver.go:69 +0x56
fyne.io/fyne/v2/internal/app.(*Lifecycle).RunEventQueue(...)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/app/lifecycle.go:111
created by fyne.io/fyne/v2/app.(*fyneApp).Run in goroutine 1
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/app/app.go:71 +0xbe

goroutine 23 [chan receive]:
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).catchTerm(0xc0002ec840)
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver_desktop.go:210 +0x74
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).Run in goroutine 1
	C:/Users/MY_USERNAME/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver.go:161 +0x68

goroutine 50 [syscall]:
os/signal.signal_recv()
	C:/Program Files/Go/src/runtime/sigqueue.go:152 +0x29
os/signal.loop()
	C:/Program Files/Go/src/os/signal/signal_unix.go:23 +0x13
created by os/signal.Notify.func1.1 in goroutine 23
	C:/Program Files/Go/src/os/signal/signal.go:152 +0x1f
--- End of Profile Output ---

How to reproduce

I am not sure how to reliably reproduce, but let me know if there is any additional debug code I could add to help find the problem.

Screenshots

No response

Example code

package main

import (
	"fmt"
	"os"
	"runtime"
	"runtime/pprof"
	"time"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"

	"utterlyeditor/gridtext"
)

func printDebug(message string) {
	// Lookup the "goroutine" profile
	p := pprof.Lookup("goroutine")
	if p == nil {
		fmt.Println("goroutine profile not found")
		return
	}

	// Write the profile to standard output (os.Stdout)
	// The debug parameter (e.g., 1 or 2) controls the verbosity of the output.
	// Use 1 for a simple list, or 2 for full stack traces.
	fmt.Printf("--- Goroutine Profile Output (%s) ---\n", message)
	err := p.WriteTo(os.Stdout, 2)
	if err != nil {
		fmt.Printf("error writing profile: %v\n", err)
	}
	fmt.Println("--- End of Profile Output ---")
}

func main() {
	application := app.New()
	updateTheme(application)
	window := application.NewWindow("Utterly Voice Editor")

	short := NewShortcuts()

	leftPanel := gridtext.NewGridText(int(PanelType_Left), short)
	rightPanel := gridtext.NewGridText(int(PanelType_Right), short)
	statusPanel := gridtext.NewGridText(int(PanelType_Status), short)

	root := container.New(NewTripleLayout(0.3),
		leftPanel, rightPanel, statusPanel)

	// create manager
	manager := NewManager(window, leftPanel, rightPanel, statusPanel)

	// register shortcuts
	short.Register(manager, window)

	window.SetContent(root)

	// TODO remember size and position
	window.Resize(fyne.NewSize(800, 600))
	window.CenterOnScreen()

	window.SetOnClosed(func() {
		// this seems to be called before renderer.Destroy().
		leftPanel.Cleanup()
		rightPanel.Cleanup()
		statusPanel.Cleanup()
		printDebug("OnClosed")
		go func() {
			retry := 5
			for i := 0; i < retry; i++ {
				routines := runtime.NumGoroutine()
				fmt.Printf("routines running: %d\n", routines)
				if routines <= 3 {
					// main, garbage collector's sweeper and scavenger?
					break
				}
				if i == retry-1 {
					printDebug("FAILED TO CLOSE")
					os.Exit(0)
				}
				time.Sleep(1 * time.Second)
			}
			fmt.Println("done diagnostic routine")
			return
		}()
	})
	window.Canvas().Focus(rightPanel)
	window.SetMaster()
	window.ShowAndRun()
	fmt.Println("done main")
}

Fyne version

fyne.io/fyne/v2 v2.7.0

Go compiler version

go version go1.24.4 windows/amd64

Operating system and version

Windows 11

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions