Skip to content

fix(linux): fix race conditions and deadlocks in event handling#5192

Draft
leaanthony wants to merge 1 commit intomasterfrom
fix/4424-event-blocks-menu
Draft

fix(linux): fix race conditions and deadlocks in event handling#5192
leaanthony wants to merge 1 commit intomasterfrom
fix/4424-event-blocks-menu

Conversation

@leaanthony
Copy link
Copy Markdown
Member

Summary

  • Fix RLock used for map deletion in mainthread_linux.go, mainthread_darwin.go, and mainthread_ios.go — map writes under RLock cause undefined behavior with concurrent readers
  • Fix DispatchWailsEvent holding windowsLock during potentially blocking ExecJS dispatch — release lock before dispatching to prevent deadlocks when the main thread also needs the lock
  • Add early unlock before Fatal in nil callback path to avoid lock leak
  • Add unit tests for lock correctness and concurrent access patterns

Fixes #4424

Test plan

  • TestMainThreadFunctionStoreLockCorrectness — concurrent callback store access with Lock (not RLock)
  • TestMainThreadFunctionStoreConcurrentReadWrite — concurrent readers and writers
  • TestDispatchWailsEventReleasesLockAfterCompletion — lock is released after dispatch
  • Integration test at v3/test/4424-event-block/main.go — manual test with event emitter + menu clicks

…ling (#4424)

This commit addresses issues that could cause menu buttons to stop responding
when events are being emitted frequently:

1. Fixed race condition in mainthread callback store (Linux, macOS, iOS):
   - Changed RLock() to Lock() when deleting from mainThreadFunctionStore
   - Using RLock for read-only operations but then calling delete() violated
     the RWMutex contract and could cause undefined behavior

2. Fixed potential deadlock in EventIPCTransport.DispatchWailsEvent:
   - Changed to snapshot windows list and release lock before dispatching
   - Previously held windowsLock.RLock() during ExecJS which blocks waiting
     for the main thread, potentially causing deadlocks if main thread
     operations needed windowsLock.Lock()

3. Added test case to reproduce the issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

# Conflicts:
#	v3/UNRELEASED_CHANGELOG.md
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8a26a28b-e597-4de3-a101-935e8a8d98ec

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4424-event-blocks-menu

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@leaanthony leaanthony changed the base branch from v3-alpha to master April 29, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v3] Event emitter blocks menu button press

1 participant