Skip to content

[Impeller] GLES: PipelineLibraryGLES pipeline map is accessed from two threads without a lock (Flutter GPU) #193745

Closed

Description

@leehack

Steps to reproduce

  1. On Linux x64, build impeller_unittests from master d03768e with the test from the code sample below added to impeller/renderer/backend/gles/test/pipeline_library_gles_unittests.cc (also once with --tsan).
  2. Run it under Xvfb with Mesa, as in CI: xvfb-run impeller_unittests --gtest_filter='*CanLookUpPipelinesWhileCreatingPipelines/OpenGLES'.

Expected results

HasPipeline and GetPipeline can run on one thread while another thread creates pipelines, as Flutter GPU does.

Actual results

PipelineLibraryGLES locks programs_ but not pipelines_, and GetPipeline inserts into pipelines_ on the calling thread (only program linking runs on the reactor). Flutter GPU calls HasPipeline and GetPipeline on the UI thread (RenderPass::GetOrCreatePipeline) while Impeller inserts variants on the raster thread.

  • The test fails in 32 of 40 runs: the reader thread misses a pipeline that already exists.
  • Under TSan, all 10 runs report the race between GetPipeline (insert) and HasPipeline (lookup).
  • With a mutex on pipelines_, it passes 40/40 and TSan reports no pipelines_ race.

This is confirmed only with this engine test on Linux (Mesa), not in an app. It is a sibling of #193721 (Metal pipelines) and #193737 (samplers).

Code sample

Test

Also needs <atomic>, <string>, <thread> and flutter/fml/synchronization/count_down_latch.h.

TEST_P(PipelineLibraryGLESTest, CanLookUpPipelinesWhileCreatingPipelines) {
  using VS = SpecConstantVertexShader;
  using FS = SpecConstantFragmentShader;
  std::shared_ptr<Context> context = GetContext();
  ASSERT_TRUE(context);
  std::optional<PipelineDescriptor> desc =
      PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
  ASSERT_TRUE(desc.has_value());
  std::shared_ptr<PipelineLibrary> library = context->GetPipelineLibrary();
  ASSERT_TRUE(library->GetPipeline(desc).Get());

  std::atomic_bool done = false;
  std::atomic_int misses = 0;
  fml::CountDownLatch reading(1);
  std::thread reader([&] {
    reading.CountDown();
    while (!done) {
      if (!library->HasPipeline(desc.value()) ||
          !library->GetPipeline(desc.value()).IsValid()) {
        misses++;
      }
    }
  });
  reading.Wait();

  for (int i = 0; i < 128; i++) {
    PipelineDescriptor variant = desc.value();
    variant.SetLabel("Variant " + std::to_string(i));
    std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline =
        library->GetPipeline(variant).Get();
    EXPECT_TRUE(pipeline && pipeline->IsValid());
  }
  done = true;
  reader.join();
  EXPECT_EQ(misses, 0);
}

Screenshots or Video

N/A

Logs

TSan, master d03768e (Linux x64, Mesa, Xvfb)
WARNING: ThreadSanitizer: data race
  Write of size 8 by main thread:
    #1 std::unordered_map<PipelineDescriptor, PipelineFuture<PipelineDescriptor>>::operator[]()
    #2 impeller::PipelineLibraryGLES::GetPipeline(PipelineDescriptor, bool, bool) pipeline_library_gles.cc:301
    #3 PipelineLibraryGLESTest_CanLookUpPipelinesWhileCreatingPipelines_Test::TestBody()
  Previous read of size 8 by thread T67:
    #1 std::unordered_map<PipelineDescriptor, PipelineFuture<PipelineDescriptor>>::find()
    #2 impeller::PipelineLibraryGLES::HasPipeline(PipelineDescriptor const&) pipeline_library_gles.cc:347
    #3 PipelineLibraryGLESTest_CanLookUpPipelinesWhileCreatingPipelines_Test::TestBody()::$_0::operator()()
pipeline_library_gles_unittests.cc: Failure
Expected equality of these values:
  misses
    Which is: 2
[  FAILED  ] Play/PipelineLibraryGLESTest.CanLookUpPipelinesWhileCreatingPipelines/OpenGLES

Flutter Doctor output

flutter doctor -v (the machine that found the related races; the GLES result comes from the engine build above)
[✓] Flutter (Channel stable, 3.47.1, on macOS 26.7 25G229 darwin-arm64, locale en-CA) [1,710ms]
    • Flutter version 3.47.1 on channel stable at /Users/<user>/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6655482ec0 (6 weeks ago), 2026-08-19 10:07:23 -0700
    • Engine revision 5d53178869
    • Dart version 3.13.1
    • DevTools version 2.60.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [4.4s]
    • Android SDK at /Users/<user>/Library/Android/sdk
    • Emulator version 36.6.11.0 (build_id 15507667) (CL:N/A)
    • Platform android-36.1, build-tools 36.1.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.10+-117844308-b1163.108)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 27.0) [4.5s]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 27A266a
    ! iOS 27.0 Simulator not installed; this may be necessary for iOS and macOS development.
      To download and install the platform, open Xcode, select Xcode > Settings > Components,
      and click the GET button for the required platform.

      For more information, please visit:
        https://developer.apple.com/documentation/xcode/installing-additional-simulator-runtimes
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [7ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (3 available) [7.3s]
    • iPhone 17 Pro (mobile) • <simulator-udid> • ios            • com.apple.CoreSimulator.SimRuntime.iOS-26-4 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 26.7 25G229 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 154.0.8037.95

[✓] Network resources [1,093ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. added
    in triage
    on Oct 5, 2026
  2. suryaKommana2662 commented on Oct 5, 2026

    @suryaKommana2662
    Contributor

    @leehack Thanks for the report. Noticed that this was tested on Flutter 3.47.1. Could you please confirm whether the issue is still reproducible on the latest stable Flutter release, 3.47.6? Once confirmed, we can route the issue to the appropriate team for further investigation.

  3. added
    waiting for response
    and removed
    in triage
    on Oct 5, 2026
  4. leehack commented on Oct 5, 2026

    @leehack
    ContributorAuthor

    @leehack Thanks for the report. Noticed that this was tested on Flutter 3.47.1. Could you please confirm whether the issue is still reproducible on the latest stable Flutter release, 3.47.6? Once confirmed, we can route the issue to the appropriate team for further investigation.

    The issue was initially reproduced on 3.47.1, and I have the SDK installed on my machine. That's why the doctor is showing the version, but it's tested and reproduced on the main branch.

    You can also see the fix PR: #193746

  5. removed
    waiting for response
    on Oct 5, 2026
  6. added
    in triage
    engine
    e: impeller
    team-engine
    and removed
    in triage
    on Oct 5, 2026
  7. added
    team-fluttergpu
    and removed
    team-engine
    on Oct 5, 2026
  8. gaaclarke commented on Oct 12, 2026

    @gaaclarke
    Member

    This code is being reworked in #194022 and may address the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: impellerengineteam-fluttergpu

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions