Skip to content

Conversation

@robert-ancell
Copy link
Contributor

gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes #173447

gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes flutter#173447
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@robert-ancell robert-ancell requested a review from mattkae August 12, 2025 04:07
@github-actions github-actions bot added engine flutter/engine related. See also e: labels. platform-linux Building on or for Linux specifically a: desktop Running on desktop labels Aug 12, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a thread-safety issue by moving the gtk_widget_queue_draw call into an idle callback, ensuring it runs on the main GTK thread. The logic for handling the first frame has also been consolidated into the new redraw_cb function. This not only fixes the bug but also improves the code's structure and thread safety regarding the have_first_frame flag. The changes are well-implemented and effectively resolve the issue.

@robert-ancell
Copy link
Contributor Author

The fix was found by enabling tsan in the Flutter engine build. It also showed some potential issues coming from the Linux task runner, which I will investigate in the future.

Copy link
Contributor

@mattkae mattkae left a comment

Choose a reason for hiding this comment

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

Just a thought, but feel free to merge!

@mattkae
Copy link
Contributor

mattkae commented Aug 12, 2025

Also - I tested and it works well for me!

CC: @loic-sharma

@stuartmorgan-g
Copy link
Contributor

test-exempt: unblocks enabling tooling that catches it

@robert-ancell robert-ancell added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 12, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Aug 12, 2025
Merged via the queue into flutter:master with commit 53676f0 Aug 12, 2025
181 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 12, 2025
@robert-ancell robert-ancell deleted the linux-threading-fixes branch August 12, 2025 23:33
@camsim99 camsim99 added the cp: beta cherry pick this pull request to beta release candidate branch label Aug 12, 2025
@flutteractionsbot
Copy link

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

@camsim99
Copy link
Contributor

@robert-ancell @loic-sharma We'll need to manually CP this to https://github.com/flutter/flutter/tree/flutter-3.35-candidate.0. Can one of you help out here? Thanks!

robert-ancell added a commit to robert-ancell/flutter that referenced this pull request Aug 12, 2025
gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes flutter#173447
@robert-ancell
Copy link
Contributor Author

@camsim99 - cherry pick in #173667

robert-ancell added a commit to robert-ancell/flutter that referenced this pull request Aug 13, 2025
gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes flutter#173447
@robert-ancell
Copy link
Contributor Author

And cherry pick for 3.36 branch as requested by @loic-sharma in #173669

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2025
auto-submit bot pushed a commit that referenced this pull request Aug 13, 2025
…ad (#173669)

Cherry pick of #173602

Impacted users: All Linux users of Flutter
Impact Description: Due to calling gtk_window_redraw on a Flutter thread a lock up may occur. The Flutter app will then become unresponsive.
Workaround: No workaround
Risk: Low - fix is to run the GTK call on the GTK thread which is what the correct behaviour should be.
Test coverage: Rendering covered by existing tests, use of thread not explicitly tested, but #173660 opened to add this in future.
Validation Steps: Run test program in #173447 which generates many frames and maximizes the chance of a lock up.
auto-submit bot pushed a commit that referenced this pull request Aug 13, 2025
…ad (#173667)

Cherry pick of #173602

Impacted users: All Linux users of Flutter
Impact Description: Due to calling gtk_window_redraw on a Flutter thread a lock up may occur. The Flutter app will then become unresponsive.
Workaround: No workaround
Risk: Low - fix is to run the GTK call on the GTK thread which is what the correct behaviour should be.
Test coverage: Rendering covered by existing tests, use of thread not explicitly tested, but #173660 opened to add this in future.
Validation Steps: Run test program in #173447 which generates many frames and maximizes the chance of a lock up.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 13, 2025
Roll Flutter from e2a347b14a18 to 34c2a3b158b2 (41 revisions)

flutter/flutter@e2a347b...34c2a3b

2025-08-13 [email protected] [ Tool ] Mark Linux_pixel_7pro linux_chrome_dev_mode as bringup (flutter/flutter#173646)
2025-08-13 [email protected] [ Widget Preview ] Move `--dtd-url` from a global flag to a `widget-preview start` option (flutter/flutter#173712)
2025-08-13 [email protected] Null aware elements clean-ups (flutter/flutter#173074)
2025-08-13 [email protected] Roll Skia from 29e3e1ab7f62 to f7fdda3cd0e6 (3 revisions) (flutter/flutter#173709)
2025-08-13 [email protected] Regular windows win32 engine (flutter/flutter#173424)
2025-08-13 [email protected] Roll Dart SDK from a098cb676fd6 to 73153bdc1459 (1 revision) (flutter/flutter#173708)
2025-08-13 [email protected] Roll Fuchsia Linux SDK from vgv-rTf7i9PfcDq2Y... to I1TfNmsqTp7t3rO8e... (flutter/flutter#173690)
2025-08-13 [email protected] Roll Skia from 1170405c30cf to 29e3e1ab7f62 (2 revisions) (flutter/flutter#173689)
2025-08-13 [email protected] Roll Dart SDK from e2b7aec7333e to a098cb676fd6 (4 revisions) (flutter/flutter#173683)
2025-08-13 [email protected] Roll Skia from d06fdf03c6a1 to 1170405c30cf (4 revisions) (flutter/flutter#173681)
2025-08-13 [email protected] Roll Skia from 9ed4b4e53db2 to d06fdf03c6a1 (11 revisions) (flutter/flutter#173661)
2025-08-12 [email protected] Fix GTK redraw call being called from non-GTK thread. (flutter/flutter#173602)
2025-08-12 [email protected] [Impeller] Apply Y coordinate scaling when sampling from the destination texture in framebuffer advanced blends (flutter/flutter#173639)
2025-08-12 [email protected] Fix directional focus in nested scrollables with different axis (flutter/flutter#172875)
2025-08-12 [email protected] [ios][tools]do not log "bonjour not found" at all (unless verbose) (flutter/flutter#173569)
2025-08-12 [email protected] Remove jetifier usages  (flutter/flutter#173548)
2025-08-12 [email protected] [ Tool ] Fix run_linux_chrome_dev_mode (flutter/flutter#173647)
2025-08-12 [email protected] [ios] Update iOS code signing CIPD instruction command (flutter/flutter#171173)
2025-08-12 [email protected] Reapply "Make device debuggable if useDwdsWebSocketConnection is true … (#173551)" (flutter/flutter#173628)
2025-08-12 [email protected] Roll Clang to 8c7a2ce01a77c96028fe2c8566f65c45ad9408d3 (flutter/flutter#173429)
2025-08-12 [email protected] [web] Fallback to CanvasKit when WebGL is not available (flutter/flutter#173629)
2025-08-12 [email protected] Roll Packages from a114ac2 to 08a9b2c (3 revisions) (flutter/flutter#173625)
2025-08-12 [email protected] [ Tool ] Fix crash from possible DDS startup race (flutter/flutter#173362)
2025-08-12 [email protected] Roll Skia from a2936eff2179 to 9ed4b4e53db2 (3 revisions) (flutter/flutter#173611)
2025-08-12 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 4 to 5 in the all-github-actions group (flutter/flutter#173606)
2025-08-12 [email protected] Roll Dart SDK from c5fe48aee60d to e2b7aec7333e (1 revision) (flutter/flutter#173604)
2025-08-12 [email protected] Roll Skia from 44bb9d908ee4 to a2936eff2179 (21 revisions) (flutter/flutter#173603)
2025-08-12 [email protected] Fix the issue of over-scrolling in SliverMainAxisGroup with a PinnedHeaderSliver. (flutter/flutter#173349)
2025-08-12 [email protected] Roll Dart SDK from b2a23936f968 to c5fe48aee60d (2 revisions) (flutter/flutter#173596)
2025-08-11 [email protected] Update CanRenderTiledTexture unit tests (flutter/flutter#173553)
2025-08-11 [email protected] Update integration test for iOS deployment workflows (flutter/flutter#173566)
2025-08-11 [email protected] Enables vulkan for PowerVR B-Series (flutter/flutter#173561)
2025-08-11 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reapply "Make device debuggable if useDwdsWebSocketConnection is true … (#173551)" (#173568)" (flutter/flutter#173587)
2025-08-11 [email protected] Roll Dart SDK from 8e882349fcab to b2a23936f968 (2 revisions) (flutter/flutter#173571)
2025-08-11 [email protected] Reapply "Make device debuggable if useDwdsWebSocketConnection is true … (#173551)" (flutter/flutter#173568)
2025-08-11 [email protected] Update CI iOS tests (flutter/flutter#173563)
2025-08-11 [email protected] Roll Packages from 34948d1 to a114ac2 (4 revisions) (flutter/flutter#173556)
2025-08-11 [email protected] Roll Fuchsia Linux SDK from HclTm0V8hgSpfqmtG... to vgv-rTf7i9PfcDq2Y... (flutter/flutter#173505)
2025-08-11 [email protected] Roll Dart SDK from 6a7ae1ffd1c9 to 8e882349fcab (2 revisions) (flutter/flutter#173499)
2025-08-11 [email protected] Update `ExpansibleController` in `ExpansionTile` `didUpdateWidget` (flutter/flutter#173175)
2025-08-11 [email protected] add format cmd to tools instruction (flutter/flutter#173428)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
...
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 14, 2025
gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes flutter#173447
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes flutter#173447
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes flutter#173447
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

Fixes flutter#173447
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
gtk_widget_queue_draw is not thread-safe, call it from an idle callback.

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

Labels

a: desktop Running on desktop cp: beta cherry pick this pull request to beta release candidate branch engine flutter/engine related. See also e: labels. platform-linux Building on or for Linux specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux desktop app just stops updating its window after a while

6 participants