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

[v3 alpha] Fix deadlock of linux dialog for multiple selections #3925

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

michael-freling
Copy link

@michael-freling michael-freling commented Dec 1, 2024

Description

The channel variable for the selections of a dialog isn't closed on Linux.
As a result, the next statement waits a value from the channel forever.

for filename := range selections {
fmt.Println(filename)
result = append(result, filename)
}

I have found no issue reported about this bug.

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux (WSL 2/Ubuntu 24.04)
> uname -a
Linux Desktop 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

wails3 doctor output
> go run ./cmd/wails3 doctor


          Wails Doctor



# System
┌──────────────────────────────────────────────────┐
| Name         | Ubuntu                            |
| Version      | 24.04                             |
| ID           | ubuntu                            |
| Branding     | 24.04.1 LTS (Noble Numbat)        |
| Platform     | linux                             |
| Architecture | amd64                             |
| CPU          | AMD Ryzen 5 3600 6-Core Processor |
| GPU 1        | Unknown                           |
| Memory       | 40GB                              |
└──────────────────────────────────────────────────┘

# Build Environment
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Wails CLI      | v3.0.0-alpha.7                                                                                                            |
| Go Version     | go1.23.2                                                                                                                  |
| -buildmode     | exe                                                                                                                       |
| -compiler      | gc                                                                                                                        |
| CGO_CFLAGS     |                                                                                                                           |
| CGO_CPPFLAGS   |                                                                                                                           |
| CGO_CXXFLAGS   |                                                                                                                           |
| CGO_ENABLED    | 1                                                                                                                         |
| CGO_LDFLAGS    |                                                                                                                           |
| DefaultGODEBUG | asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1 |
| GOAMD64        | v1                                                                                                                        |
| GOARCH         | amd64                                                                                                                     |
| GOOS           | linux                                                                                                                     |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────────────────────┐
| gcc        | 12.10ubuntu1                                             |
| gtk3       | 3.24.41-4ubuntu1.2                                       |
| npm        |                                                          |
| pkg-config | not installed. Install with: sudo apt install pkg-config |
| webkit2gtk | 2.46.3-0ubuntu0.24.04.1                                  |
└─────────────────────── * - Optional Dependency ───────────────────────┘

# Diagnosis
 WARNING  There are some items above that need addressing!

Need documentation? Run: wails3 docs

 ♥   If Wails is useful to you or your company, please consider sponsoring the project: wails3 sponsor

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Added support for Linux packaging formats (deb, rpm, arch) and Darwin universal builds.
    • Introduced new commands for updating build assets and generating runtime.
    • New options for Windows autofill and password autosave capabilities.
    • Enhanced drag-and-drop functionality and window event handling for Linux applications.
    • Added the ability to retrieve the window calling a service method.
  • Bug Fixes

    • Resolved a deadlock issue in the Linux dialog for multiple selections and various platform-specific application behavior fixes.
  • Changes

    • Modified application startup behavior to improve error handling and service shutdown processes.
    • Updated systray click messaging for better user interaction alignment.
    • Refactored asset embedding and upgraded dependencies for improved performance.

Copy link
Contributor

coderabbitai bot commented Dec 1, 2024

Walkthrough

The pull request updates the changelog and modifies the linux_cgo.go file to enhance functionality and user experience. Key additions include support for Linux packaging formats, new commands for build asset updates and runtime generation, and several new methods and options in the application package. The linux_cgo.go file sees improvements in handling user interactions, window events, and drag-and-drop functionality, alongside updates to signal handlers and dialog management.

Changes

File Path Change Summary
mkdocs-website/docs/en/changelog.md Updated changelog to include new features, changes, and fixes across various categories.
v3/pkg/application/linux_cgo.go Added functions for drag-and-drop handling, window events, and improved dialog management; updated signal handlers.

Possibly related PRs

Suggested reviewers

  • leaanthony

🐰 In the meadow, changes bloom,
New commands and fixes chase away gloom.
With drag-and-drop, the windows dance,
A joyful leap, a happy chance!
Let's hop along, embrace the cheer,
For every update brings us near! 🌼


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>, please review it.
    • 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 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 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 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 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.

@michael-freling michael-freling changed the title [v3 alpha] Fix deadlock of a linux dialog for multiple selection [v3 alpha] Fix deadlock of linux dialog for multiple selections Dec 1, 2024
@michael-freling michael-freling marked this pull request as ready for review December 1, 2024 22:58
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

🧹 Outside diff range and nitpick comments (3)
mkdocs-website/docs/en/changelog.md (1)

48-48: Consider enhancing the changelog entry with more technical details.

While the entry correctly documents the fix, it would be more helpful for future reference to include details about the root cause. Consider expanding it to:

- - Fixed deadlock of linux dialog for multiple selections by @michael-freling in [#3925](https://github.com/wailsapp/wails/pull/3925)
+ - Fixed deadlock in Linux dialog for multiple selections caused by unclosed channel variable by @michael-freling in [#3925](https://github.com/wailsapp/wails/pull/3925)

This addition provides valuable context about the specific issue that was fixed.

v3/pkg/application/linux_cgo.go (2)

Line range hint 1481-1499: Avoid global variables for debounce logic to prevent concurrency issues

The variables debounceTimer and isDebouncing are declared at the package level, which can lead to race conditions when multiple windows are involved. It's recommended to move these variables into the linuxWebviewWindow struct to ensure thread safety.

Apply the following changes to encapsulate the debounce logic within each window instance:

- var debounceTimer *time.Timer
- var isDebouncing bool = false

+ // Add these fields to the linuxWebviewWindow struct
+ type linuxWebviewWindow struct {
+     // ... existing fields ...
+     debounceTimer *time.Timer
+     isDebouncing  bool
+     // ... existing fields ...
+ }

Update the onKeyPressEvent function to use the window-specific variables:

func onKeyPressEvent(_ *C.GtkWidget, event *C.GdkEventKey, userData C.uintptr_t) C.gboolean {
+   windowID := uint(C.uint(userData))
+   window := globalApplication.getWindowForID(windowID)
+   if window == nil {
+       return C.gboolean(0)
+   }
+   lw, ok := window.(*WebviewWindow).impl.(*linuxWebviewWindow)
+   if !ok {
+       return C.gboolean(0)
+   }

-   if isDebouncing {
-       debounceTimer.Reset(50 * time.Millisecond)
+   if lw.isDebouncing {
+       lw.debounceTimer.Reset(50 * time.Millisecond)
        return C.gboolean(0)
    }

-   isDebouncing = true
-   debounceTimer = time.AfterFunc(50*time.Millisecond, func() {
-       isDebouncing = false
+   lw.isDebouncing = true
+   lw.debounceTimer = time.AfterFunc(50*time.Millisecond, func() {
+       lw.isDebouncing = false
    })

-   windowID := uint(C.uint(userData))
    if accelerator, ok := getKeyboardState(event); ok {
        windowKeyEvents <- &windowKeyEvent{
            windowId:          windowID,
            acceleratorString: accelerator,
        }
    }
    return C.gboolean(0)
}

Line range hint 1358-1365: Correct the zoom factor in zoomOut method

In the zoomOut method, multiplying the zoom level by a negative factor -1.10 is incorrect and can cause unexpected behavior. To decrease the zoom level properly, you should divide the current zoom level by a positive zoom factor.

Apply the following changes to fix the zoom in and zoom out functionality:

func (w *linuxWebviewWindow) zoomIn() {
-   ZoomInFactor := 1.10
+   zoomFactor := 1.10
    w.setZoom(w.getZoom() * zoomFactor)
}

func (w *linuxWebviewWindow) zoomOut() {
-   ZoomInFactor := -1.10
-   w.setZoom(w.getZoom() * ZoomInFactor)
+   zoomFactor := 1.10
+   w.setZoom(w.getZoom() / zoomFactor)
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8444ccf and 93a90c2.

📒 Files selected for processing (2)
  • mkdocs-website/docs/en/changelog.md (1 hunks)
  • v3/pkg/application/linux_cgo.go (1 hunks)
🔇 Additional comments (1)
mkdocs-website/docs/en/changelog.md (1)

Line range hint 1-24: LGTM! Changelog follows best practices.

The changelog is well-structured and follows the Keep a Changelog format. It properly categorizes changes, includes clear attributions, and maintains consistent formatting throughout.

🧰 Tools
🪛 LanguageTool

[duplication] ~47-~47: Possible typo: you repeated a word
Context: ...ny](https://github.com/leaanthony) ### Fixed - Fixed deadlock of linux dialog for multiple s...

(ENGLISH_WORD_REPEAT_RULE)

@leaanthony
Copy link
Member

Thanks for taking the time to open this. Looks like there's a merge conflict. Once that's fixed, and @atterpac is happy with it, we can merge it 🚀

auto-merge was automatically disabled December 3, 2024 13:55

Head branch was pushed to by a user without write access

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

🧹 Outside diff range and nitpick comments (3)
v3/pkg/application/linux_cgo.go (3)

Line range hint 988-992: Simplify the isVisible function by returning the boolean expression directly

The isVisible function can be simplified to return the result of the comparison directly, improving code readability.

Apply this diff to simplify the function:

-func (w *linuxWebviewWindow) isVisible() bool {
-	if C.gtk_widget_is_visible(w.gtkWidget()) == 1 {
-		return true
-	}
-	return false
+func (w *linuxWebviewWindow) isVisible() bool {
+	return C.gtk_widget_is_visible(w.gtkWidget()) == 1
 }

Line range hint 1664-1681: Avoid unnecessary goroutine in runChooserDialog to prevent potential deadlocks

The use of go func() inside InvokeAsync may lead to concurrency issues or potential deadlocks. Since InvokeAsync already handles asynchronous execution, starting a new goroutine is unnecessary.

Apply this diff to remove the redundant goroutine:

     InvokeAsync(func() {
         response := C.gtk_dialog_run((*C.GtkDialog)(fc))
-        go func() {
             if response == C.GTK_RESPONSE_ACCEPT {
                 filenames := C.gtk_file_chooser_get_filenames((*C.GtkFileChooser)(fc))
                 iter := filenames
                 count := 0
                 for {
                     selections <- buildStringAndFree(C.gpointer(iter.data))
                     iter = iter.next
                     if iter == nil || count == 1024 {
                         break
                     }
                     count++
                 }
             }
             close(selections)
-        }()
     })

Line range hint 1819-1825: Remove commented code to improve code cleanliness

The methods undo, redo, and delete contain commented-out code. It's good practice to remove such code to maintain code clarity and cleanliness.

Apply this diff to clean up the methods:

 func (w *linuxWebviewWindow) undo() {
-	//C.webkit_web_view_execute_editing_command(w.webview, C.WEBKIT_EDITING_COMMAND_UNDO)
 }
 
 func (w *linuxWebviewWindow) redo() {
-}
+}
 
 func (w *linuxWebviewWindow) delete() {
-}
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 74ac939 and 7b4befb.

📒 Files selected for processing (2)
  • mkdocs-website/docs/en/changelog.md (1 hunks)
  • v3/pkg/application/linux_cgo.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • mkdocs-website/docs/en/changelog.md

@michael-freling
Copy link
Author

@leaanthony Thank you. I resolved the conflict.

@atterpac atterpac merged commit 830f702 into wailsapp:v3-alpha Dec 3, 2024
8 checks passed
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.

3 participants