diff --git a/v2/internal/frontend/runtime/events.go b/v2/internal/frontend/runtime/events.go index 2725817ce..ac9d6299c 100644 --- a/v2/internal/frontend/runtime/events.go +++ b/v2/internal/frontend/runtime/events.go @@ -69,6 +69,7 @@ func (e *Events) OffAll() { for eventName := range e.listeners { delete(e.listeners, eventName) } + e.notifyLock.Unlock() } // NewEvents creates a new log subsystem @@ -115,6 +116,8 @@ func (e *Events) unRegisterListener(eventName string) { // Notify backend for the given event name func (e *Events) notifyBackend(eventName string, data ...interface{}) { + e.notifyLock.Lock() + defer e.notifyLock.Unlock() // Get list of event listeners listeners := e.listeners[eventName] @@ -123,9 +126,6 @@ func (e *Events) notifyBackend(eventName string, data ...interface{}) { return } - // Lock the listeners - e.notifyLock.Lock() - // We have a dirty flag to indicate that there are items to delete itemsToDelete := false @@ -163,9 +163,6 @@ func (e *Events) notifyBackend(eventName string, data ...interface{}) { delete(e.listeners, eventName) } } - - // Unlock - e.notifyLock.Unlock() } func (e *Events) AddFrontend(appFrontend frontend.Frontend) { diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 9b4bc9287..540db5b16 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed `undo`/`redo` on macOS. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2430) - Fixed `Events*` runtime functions in JavaScript not returning the function to cancel the watcher. Fixed by @zllovesuki in [PR](https://github.com/wailsapp/wails/pull/2434) - Fixed AppOptions merging defaults when a custom logger is used. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2452) +- Fixed race condition and missing unlock of mutex in events handling. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2453) ## v2.3.0 - 2022-12-29