Skip to content

#511: the UI update should in the main loop#724

Merged
lidaobing merged 3 commits into
mainfrom
bf_511_crash
Jul 6, 2026
Merged

#511: the UI update should in the main loop#724
lidaobing merged 3 commits into
mainfrom
bf_511_crash

Conversation

@lidaobing

@lidaobing lidaobing commented Jul 6, 2026

Copy link
Copy Markdown
Member

/close #511

Summary by Sourcery

Ensure updating pal entries in the UI is dispatched to the main thread for thread-safe UI refreshes.

Bug Fixes:

  • Fix UI thread-safety issue by invoking pal list updates through the GLib main context instead of directly from the core thread.

Enhancements:

  • Introduce a dedicated UiCoreThread context and helper callback to schedule pal list updates on the UI/main loop.

@sourcery-ai

sourcery-ai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures that UI list updates for pals are dispatched via the GLib main loop instead of running directly in the core thread, adding a small context struct and a dedicated UI update method while removing an unused header include.

Sequence diagram for pal list UI update via GLib main loop

sequenceDiagram
  participant CoreThread
  participant UiCoreThread
  participant GLibMainContext

  CoreThread->>UiCoreThread: UpdatePalToList(palKey)
  UiCoreThread->>CoreThread: CoreThread::UpdatePalToList(palKey)
  UiCoreThread->>GLibMainContext: g_main_context_invoke(NULL, iptux_uithread_update_pal_to_list, ctx)
  GLibMainContext->>UiCoreThread: iptux_uithread_update_pal_to_list(ctx)
  UiCoreThread->>UiCoreThread: UpdatePalToListInUI(palKey)
Loading

File-Level Changes

Change Details Files
Dispatch pal list UI updates via GLib main loop to ensure thread-safe UI modifications.
  • Introduce UiCoreThreadCtx struct to carry UiCoreThread instance and PalKey into the GLib callback.
  • Add static callback function iptux_uithread_update_pal_to_list that calls the new UI-specific update method and frees the context.
  • Modify UiCoreThread::UpdatePalToList to queue the UI update via g_main_context_invoke using the context struct.
  • Add UiCoreThread::UpdatePalToListInUI method containing the previous UI list update logic, now called from the main-loop callback.
  • Remove unused include from UiCoreThread.cpp.
src/iptux/UiCoreThread.cpp
src/iptux/UiCoreThread.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider avoiding the heap allocation and manual delete for UiCoreThreadCtx by either capturing this/palKey in a lambda passed to g_main_context_invoke or using a smart pointer to manage the context lifetime more safely.
  • The C-style cast in iptux_uithread_update_pal_to_list (auto* ctx = (UiCoreThreadCtx*)data;) could be replaced with a static_cast to improve type safety and readability.
  • It may be clearer to mark UpdatePalToListInUI as a private helper and add a brief comment indicating it must only be called from the main/UI thread, since UpdatePalToList now ensures thread-safe invocation via g_main_context_invoke.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider avoiding the heap allocation and manual delete for UiCoreThreadCtx by either capturing `this`/palKey in a lambda passed to `g_main_context_invoke` or using a smart pointer to manage the context lifetime more safely.
- The C-style cast in `iptux_uithread_update_pal_to_list` (`auto* ctx = (UiCoreThreadCtx*)data;`) could be replaced with a `static_cast` to improve type safety and readability.
- It may be clearer to mark `UpdatePalToListInUI` as a private helper and add a brief comment indicating it must only be called from the main/UI thread, since `UpdatePalToList` now ensures thread-safe invocation via `g_main_context_invoke`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Test Results

69 tests  ±0   69 ✅ ±0   3s ⏱️ ±0s
32 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit d30a27b. ± Comparison against base commit fed01c2.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.99%. Comparing base (fed01c2) to head (d30a27b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #724      +/-   ##
==========================================
+ Coverage   51.75%   51.99%   +0.23%     
==========================================
  Files          64       64              
  Lines        8704     8714      +10     
==========================================
+ Hits         4505     4531      +26     
+ Misses       4199     4183      -16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a GTK UI thread-safety issue by dispatching pal-list UI refresh work onto the GLib main context rather than performing UI updates directly from the core/network thread.

Changes:

  • Route UiCoreThread::UpdatePalToList(...) updates through g_main_context_invoke() so UI refresh happens on the main loop.
  • Introduce a small invoke-context struct and UI-thread callback trampoline.
  • Add a dedicated UpdatePalToListInUI(...) helper to separate core updates from UI updates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/iptux/UiCoreThread.h Adds a UI-thread helper entrypoint for pal-list updates.
src/iptux/UiCoreThread.cpp Schedules pal-list UI updates onto the GLib main loop via g_main_context_invoke().

Comment thread src/iptux/UiCoreThread.cpp
Comment thread src/iptux/UiCoreThread.h
Comment on lines 46 to 51
void ClearAllPalFromList() override;
void UpdatePalToList(PalKey palKey) override;
void UpdatePalToListInUI(PalKey palKey);
void UpdatePalToList(in_addr ipv4) override {
UpdatePalToList(PalKey(ipv4, port()));
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

@lidaobing
lidaobing merged commit 6b98e8e into main Jul 6, 2026
19 of 21 checks passed
@lidaobing
lidaobing deleted the bf_511_crash branch July 6, 2026 05:28
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.

In linux, open a chat window with a mac user, within a minute, the app crashes

2 participants