Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Address Mac CGO Crash #3590

Merged
merged 5 commits into from
Aug 20, 2024
Merged

Conversation

leaanthony
Copy link
Member

@leaanthony leaanthony commented Jul 4, 2024

Description

This fix copies Go memory to C memory to ensure that it does not move during a request.

Fixes #3550

Summary by CodeRabbit

  • Bug Fixes
    • Resolved a CGO memory issue on Darwin, ensuring more stable and efficient memory management.

Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Warning

Rate limit exceeded

@leaanthony has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 56 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 407109f and 13c408a.

Walkthrough

The changes address a CGO memory issue on macOS that caused application crashes when handling middleware responses. The responseWriter function in responsewriter_darwin.go was updated to copy data to a C array before passing it to a C function, fixing the issue.

Changes

File Change Summary
v2/pkg/assetserver/webview/responsewriter_darwin.go Modified the responseWriter function to handle buf by creating a C array and copying the data before passing it to a C function.
website/src/pages/changelog.mdx Added a changelog entry detailing the fix for the CGO memory issue on Darwin contributed by @leaanthony in PR #3590.

Assessment against linked issues

Objective Addressed Explanation
Fix the macOS panic caused by serving middleware response (#3550)
Ensure no Go pointers are passed directly to C in the responseWriter function (#3550)

Poem

In the land of bytes and data flow,
CodeRabbit fixed where bugs did grow.
With C arrays and careful write,
Middleware shines in Mac's soft light.
Crash no more, the code does show,
Wails on macOS, with pride, aglow.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

cloudflare-workers-and-pages bot commented Jul 4, 2024

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: 13c408a
Status: ✅  Deploy successful!
Preview URL: https://af102338.wails.pages.dev
Branch Preview URL: https://v2-bugfix-3550-macos-cgo-err.wails.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
website/src/pages/changelog.mdx (2)

17-17: Fix repeated word "issue".

There is a repeated word "issue" in the changelog entry.

- Fixed CGO memory issue on Darwin by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3590)
+ Fixed CGO memory issue on Darwin by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3590)
Tools
LanguageTool

[duplication] ~17-~17: Possible typo: you repeated a word
Context: ... vulnerabilities. ## [Unreleased] ### Fixed - Fixed CGO memory issue on Darwin by @leaantho...

(ENGLISH_WORD_REPEAT_RULE)


18-18: Fix repeated word "issue".

There is a repeated word "issue" in the changelog entry.

- Fixed CGO memory issue on Darwin by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3590)
+ Fixed CGO memory issue on Darwin by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3590)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9b01922 and 735396d.

Files selected for processing (2)
  • v2/pkg/assetserver/webview/responsewriter_darwin.go (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
Additional context used
LanguageTool
website/src/pages/changelog.mdx

[duplication] ~17-~17: Possible typo: you repeated a word
Context: ... vulnerabilities. ## [Unreleased] ### Fixed - Fixed CGO memory issue on Darwin by @leaantho...

(ENGLISH_WORD_REPEAT_RULE)


[duplication] ~22-~22: Possible typo: you repeated a word
Context: ...pull/3590) ## v2.9.1 - 2024-06-18 ### Fixed - Fixed build issues on Linux for some glibc ve...

(ENGLISH_WORD_REPEAT_RULE)

Additional comments not posted (4)
v2/pkg/assetserver/webview/responsewriter_darwin.go (4)

106-106: Ensure that contentLen is correctly calculated.

The variable contentLen is set to 0 if buf is nil. This is correct, but ensure that buf is properly checked before use.


112-112: Verify the safety of unsafe.Pointer usage.

Ensure that buf is not empty and that &buf[0] is a valid pointer. This can prevent potential runtime panics.


114-115: Handle potential errors from URLSchemeTaskDidReceiveData.

The function URLSchemeTaskDidReceiveData returns a boolean indicating success or failure. Ensure proper error handling if it returns false.


118-119: Handle potential errors from URLSchemeTaskDidReceiveData with nil data.

The function URLSchemeTaskDidReceiveData is called with nil and 0 if contentLen is 0. Ensure proper error handling if it returns false.

v2/pkg/assetserver/webview/responsewriter_darwin.go Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

sonarcloud bot commented Jul 5, 2024

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 735396d and 407109f.

Files selected for processing (1)
  • v2/pkg/assetserver/webview/responsewriter_darwin.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • v2/pkg/assetserver/webview/responsewriter_darwin.go

// Create a C array to hold the data
cBuf := C.malloc(C.size_t(contentLen))
if cBuf == nil {
return 0, fmt.Errorf("memory allocation failed for %d bytes", contentLen)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt import is missing so compile fails. Fixed this in my fork: v2-bugfix/3550-macos-cgo-error...makew0rld:wails:patch-1

@leaanthony leaanthony enabled auto-merge (squash) August 18, 2024 11:15
Copy link

sonarcloud bot commented Aug 18, 2024

@leaanthony leaanthony enabled auto-merge (squash) August 18, 2024 11:18
@makew0rld
Copy link

@leaanthony not sure what's up with auto-merge but this is good to be merged. Would appreciate a release but no problem if it's not convenient.

@leaanthony leaanthony merged commit 3f83b42 into master Aug 20, 2024
15 checks passed
@leaanthony leaanthony deleted the v2-bugfix/3550-macos-cgo-error branch August 20, 2024 08:12
@leaanthony
Copy link
Member Author

Thanks for chasing this up!

therealsamf pushed a commit to therealsamf/wails that referenced this pull request Aug 29, 2024
* Copy request to Go memory

* Update changelog.mdx

* Update v2/pkg/assetserver/webview/responsewriter_darwin.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix import

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

macOS panic when serving middleware response
2 participants