Skip to content

Conversation

@leaanthony
Copy link
Member

@leaanthony leaanthony commented Jul 21, 2025

Summary

This PR fixes a crash that occurs when closing a window while there are pending async Go-bound function calls.

Root Cause

When a window is closed while async Go method calls are still pending, the application crashes because:

  1. The messageProcessor was created but never stored as a field on the App struct
  2. There was no mechanism to cancel pending async calls when a window is destroyed
  3. The window could be destroyed while async operations were still trying to send responses back

Fix

  • Added messageProcessor field to the App struct to store the MessageProcessor instance
  • Implemented CancelWindowCalls method in MessageProcessor to track and cancel pending calls per window
  • Added call to CancelWindowCalls in the window's destroy() method
  • Added safety checks to prevent sending responses to destroyed windows

Testing

Updated the issue-4353 test and example to use the correct Wails v3 APIs (they were using v2-style APIs).

To test:

  1. Run the example in v3/examples/issue-4353/
  2. Click "Start 5-Second Async Operation"
  3. Immediately click "Close Window"
  4. The window should close without crashing

Fixes #4353

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Resolved a crash that could occur when closing a window with pending asynchronous operations.
  • Improvements

    • Enhanced cleanup and safety checks to ensure all pending asynchronous operations are properly cancelled when a window is closed.
    • Improved window lifecycle management to prevent operations on destroyed windows and ensure proper deregistration from the window manager.

- Add messageProcessor field to App struct to store MessageProcessor instance
- Implement CancelWindowCalls method to cancel pending async calls for a window
- Track window calls in MessageProcessor with windowCalls map
- Call CancelWindowCalls in window destroy() method to prevent crashes
- Add safety checks for destroyed windows in CallError and CallResponse
- Update issue-4353 test and example to use correct Wails v3 APIs

Fixes #4353

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

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

This change implements a fix for a crash that occurred when closing a window with pending asynchronous Go-bound function calls. It introduces per-window tracking and cancellation of running async calls, ensures proper cleanup during window destruction, and adds safety checks to prevent JavaScript execution on destroyed windows. The changelog is updated to reflect this fix.

Changes

File(s) Change Summary
v3/UNRELEASED_CHANGELOG.md Added a bug fix entry describing the crash fix for window closure with pending async calls.
v3/pkg/application/application.go Added messageProcessor field to App struct and initialized it during app creation.
v3/pkg/application/messageprocessor.go Added windowCalls map to MessageProcessor and a CancelWindowCalls method to cancel all calls tied to a window.
v3/pkg/application/messageprocessor_call.go Modified call tracking to associate running calls with window IDs and clean up per-window call maps on completion.
v3/pkg/application/webview_window.go Enhanced CallError and CallResponse to check window state; destroy now cancels all pending async calls for the window before cleanup.
v3/pkg/application/webview_window_darwin.go Updated destroy to remove the window from the global window manager before native destruction.

Sequence Diagram(s)

sequenceDiagram
    participant JS as JavaScript
    participant App as App
    participant MP as MessageProcessor
    participant Win as WebviewWindow

    JS->>App: Async Go-bound call (with windowID)
    App->>MP: Register running call (windowID, callID)
    Note over MP: Track call under windowID

    JS->>Win: User closes window
    Win->>MP: CancelWindowCalls(windowID)
    MP->>MP: Cancel all running calls for windowID
    MP->>App: Remove call tracking

    MP->>Win: (If call completes after window closed)
    Win->>Win: Check if destroyed<br/>Skip JS execution if destroyed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~40 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix crash when closing macOS window with pending async Go-bound function calls (#4353)
Prevent execution of JavaScript callbacks on destroyed windows (#4353)
Cancel all pending async calls related to a window upon its destruction (#4353)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Suggested labels

lgtm

Poem

A window closed, async calls in flight,
No more crashes in the night!
Each call now tracked, per window, you see—
Cancelled with care, crash-free as can be.
🐇✨
Hopping along, the code is sound,
No more bugs come hopping around!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76bb374 and 54ac2c3.

📒 Files selected for processing (3)
  • v3/pkg/application/application.go (2 hunks)
  • v3/pkg/application/webview_window.go (3 hunks)
  • v3/pkg/application/webview_window_darwin.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • v3/pkg/application/application.go
  • v3/pkg/application/webview_window_darwin.go
  • v3/pkg/application/webview_window.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Cloudflare Pages
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v3-alpha-bugfix/issue-4353

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the Documentation Improvements or additions to documentation label Jul 21, 2025
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 21, 2025

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: 54ac2c3
Status: ✅  Deploy successful!
Preview URL: https://8a1e5f13.wails.pages.dev
Branch Preview URL: https://v3-alpha-bugfix-issue-4353.wails.pages.dev

View logs

@leaanthony leaanthony marked this pull request as ready for review July 21, 2025 21:03
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Bug Something isn't working v3 labels Jul 21, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Documentation Improvements or additions to documentation MacOS size:M This PR changes 30-99 lines, ignoring generated files. v3-alpha v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants