5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:51:44 +08:00

[events] Fix race condition and missing unlock of mutex (#2453)

This commit is contained in:
stffabi 2023-03-07 10:40:33 +01:00 committed by GitHub
parent d7a8406640
commit c11c32940e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View File

@ -69,6 +69,7 @@ func (e *Events) OffAll() {
for eventName := range e.listeners { for eventName := range e.listeners {
delete(e.listeners, eventName) delete(e.listeners, eventName)
} }
e.notifyLock.Unlock()
} }
// NewEvents creates a new log subsystem // NewEvents creates a new log subsystem
@ -115,6 +116,8 @@ func (e *Events) unRegisterListener(eventName string) {
// Notify backend for the given event name // Notify backend for the given event name
func (e *Events) notifyBackend(eventName string, data ...interface{}) { func (e *Events) notifyBackend(eventName string, data ...interface{}) {
e.notifyLock.Lock()
defer e.notifyLock.Unlock()
// Get list of event listeners // Get list of event listeners
listeners := e.listeners[eventName] listeners := e.listeners[eventName]
@ -123,9 +126,6 @@ func (e *Events) notifyBackend(eventName string, data ...interface{}) {
return return
} }
// Lock the listeners
e.notifyLock.Lock()
// We have a dirty flag to indicate that there are items to delete // We have a dirty flag to indicate that there are items to delete
itemsToDelete := false itemsToDelete := false
@ -163,9 +163,6 @@ func (e *Events) notifyBackend(eventName string, data ...interface{}) {
delete(e.listeners, eventName) delete(e.listeners, eventName)
} }
} }
// Unlock
e.notifyLock.Unlock()
} }
func (e *Events) AddFrontend(appFrontend frontend.Frontend) { func (e *Events) AddFrontend(appFrontend frontend.Frontend) {

View File

@ -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 `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 `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 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 ## v2.3.0 - 2022-12-29