Repository navigation
fix(v3/events): read event hooks under hookLock in Emit - #6276
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Snapshot hooks during emission v3/pkg/application/events.go, v3/pkg/application/events_test.go, v3/UNRELEASED_CHANGELOG.md |
Emit copies the event’s hooks under a read lock, then invokes the copy. The test emits events while registering and removing a hook. The changelog describes the data race. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: leaanthony
Merge Risk: 
Minimal · previous review ad971
-
This change fixes a data race in event hook emission. No actionable merge-blocking risk was found in the supplied changes.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the race condition, implementation, motivation, testing, platform, and checklist status. It identifies related issue
#6275and provides sufficient test configuration, although it does not include wails doctor output.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit watched the hooks go by,
While emitters hopped beneath the sky.
A locked snapshot kept their place,
Then callbacks ran at their own pace.
The changelog noted what had been,
And rabbits cheered the threads serene.
With ears held high, they closed the scene.
Comment @coderabbitai help to get the list of available commands.
|
Automated GA-readiness test result for head
Neither failure comes from this PR. The branch is based on 91a74c4, and the updater test failure there was fixed on master by #6278 (master ba77efe passes it on both nodes). The |
7e126e2 to
ad9714c
Compare
|
Automated GA-readiness test result for head
This matches the master baseline (d8f3336) on both nodes: master shows the same Windows-only |
Emit read e.hooks without taking hookLock, while RegisterHook appends to the slice and its remover rewrites it in place with slices.DeleteFunc (which also zeroes the tail). A concurrent Emit could race with both and observe a cleared entry. Emit now copies the event's hooks under a read lock and runs the copy.
ad9714c to
5a50640
Compare
…event hooks under hookLock in Emit
Resolves the conflict in v3/pkg/application/events_test.go with wailsapp#6276, which added TestEventProcessorRegisterHookWhileEmitting where this branch added its ordering tests: both are kept. events.go merged cleanly (wailsapp#6276's hook copy under hookLock in Emit; this branch's per-listener delivery in dispatchEventToListeners). Checked locally on go1.26.10 (the toolchain v3/go.mod pins): go vet and go test of ./pkg/application/... and ./internal/mailbox/..., and the event and mailbox tests three times under -race.
Description
EventProcessor.Emitreadse.hookswithout takinghookLock, whileRegisterHookappends to the hook slice under the lock and the function it returns rewrites that slice in place withslices.DeleteFunc(which also zeroes the tail since Go 1.22). AnEmitrunning concurrently with registering or removing a hook therefore races with both, and can observe a cleared entry.Emitnow copies the event's hooks underhookLock.RLock()and runs the copy, the same snapshot approachEventManageralready uses for application event listeners. Hooks still run synchronously and in registration order, and a hook can still register or remove hooks without deadlocking because the lock is released before any hook runs.Found while working on #6275 (Go listener ordering, follow-up to #5757); kept separate because it is an independent bug.
Type of change
How Has This Been Tested?
TestEventProcessorRegisterHookWhileEmittingemits in a loop while registering and removing hooks on another goroutine.Before the fix,
go test -race ./pkg/application/ -run TestEventProcessorRegisterHookWhileEmittingreportsDATA RACEbetweenevents.go:157(Emit) andevents.go:219/228(RegisterHookand its remover).After the fix: clean with
-race -count=20, and the whole./pkg/application/suite passes with-race.Windows
macOS
Linux
Linux: Fedora 43, Go 1.26.7 (the change is platform-independent Go).
Test Configuration
Platform-independent change; tested with
go test -raceon Linux (Fedora 43, x86_64, Go 1.26.7).Checklist:
Summary by CodeRabbit