Skip to content

Data race in Fyne API during app shutdown with multiple goroutines #5748

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

Open
2 tasks done
ErikKalkoken opened this issue May 20, 2025 · 3 comments
Open
2 tasks done
Labels
unverified A bug that has been reported but not verified

Comments

@ErikKalkoken
Copy link
Contributor

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

When accessing the Fyne API from multiple goroutines during app shutdown it results in multiple data races (as reported by go run -race).

This includes writes to maps, which may result in in app crashes / panics.

I was not able to get any data races with only one goroutine.

Example log: dataraces.txt

How to reproduce

Run the code example with go run -race .

This reliable produces multiple data races.

Screenshots

No response

Example code

package main

import (
	"time"

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

func main() {
	a := app.New()
	w := a.NewWindow("Fyne-Playground")
	l := widget.NewLabel("dummy")
	c := container.NewCenter(l)
	w.SetContent(c)
	w.Resize(fyne.NewSize(400, 300))
	go func() {
		t1 := time.NewTicker(100 * time.Millisecond)
		for {
			fyne.Do(func() {
				l.SetText("xx")
			})
			<-t1.C
		}
	}()
	go func() {
		t1 := time.NewTicker(100 * time.Millisecond)
		for {
			fyne.Do(func() {
				l.SetText("xx")
			})
			<-t1.C
		}
	}()
	w.ShowAndRun()
}

Fyne version

2.6.1

Go compiler version

1.24.3

Operating system and version

Ubuntu 22.04

Additional Information

No response

@ErikKalkoken ErikKalkoken added the unverified A bug that has been reported but not verified label May 20, 2025
@dweymouth
Copy link
Contributor

If you move <-t1.C before the fyne.Do call in each loop (so that they will begin by sleeping 100 ms) does it still report a race, or does it test clean? If the latter, it may be a smaller, simpler to fix issue with how fyne.Do behaves when invoked before the app loop begins.

@ErikKalkoken
Copy link
Contributor Author

I moved both channel receives before the fyne.Do callbacks and it still reports a data races.

@imsgit
Copy link

imsgit commented May 27, 2025

Confirm
While stopping IDE even the code wrapped with fyne.Do throws errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

3 participants