Skip to content

"Stream already subscribed" in Flutter Widget preview #192424

Closed

Description

@DanTup

Steps to reproduce

I don't have great steps to reproduce, it's somewhat inconsistent and I can only repo on GH Actions and in a local container (with a wonky setup).

I'm running Dart-Code's E2E Playwright tests that try to verify the widget preview, and sometimes it crashes.

Logs look approximately like:

    [Info] Spawning flutter with args ["widget-preview","start","--machine","--web-server",...]
    [Info] <== widget_preview.initializing
    [Info] "Launching analysis server..."
    [warning] "Lost connection to the Dart Tooling Daemon (DTD). Live preview updates are paused.
      Details: JSON-RPC error 103: Stream already subscribed"
    [Info] "Launching the Widget Preview Scaffold on Web Server..."
    [Info] "Launching lib/main.dart on Web Server in debug mode..."
    [Info] "Triggering reload..." x3 (all in the same second)
    [error] "Flutter failed to read file at /tmp/flutter_tools.XXX/web_entrypoint.dart.
      PathNotFoundException ... errno 2"
    [Error] Process flutter/bin/flutter terminated! 1
    [Error] Widget Preview server process terminated

Looking in dtd_services my suspicion is a race condition in calls to _waitForLspService() being called twice:

  1. First by getFlutterWidgetPreviews() as the preview starts loading
  2. Next by getFlutterWidgetPreviewsForFile() as a file is opened

_waitForLspService bails out if _lspServiceAvailable is already set. However it's set after await _dtd!.streamListen(kServiceStream);. This means if two calls to this function occur at the same time, both could call streamListen().

@bkonyi WDYT, does this sound plausible? I haven't fully debugged this yet, because I can only repro it in containers on remote machines, but I'll try to hack in some logging to verify if that's what's happening.

Expected results

No crash :)

Actual results

Process crashes.

Code sample

N/A

Screenshots or Video

N/A

Logs

Logs
    [Info] Spawning flutter with args ["widget-preview","start","--machine","--web-server",...]
    [Info] <== widget_preview.initializing
    [Info] "Launching analysis server..."
    [warning] "Lost connection to the Dart Tooling Daemon (DTD). Live preview updates are paused.
      Details: JSON-RPC error 103: Stream already subscribed"
    [Info] "Launching the Widget Preview Scaffold on Web Server..."
    [Info] "Launching lib/main.dart on Web Server in debug mode..."
    [Info] "Triggering reload..." x3 (all in the same second)
    [error] "Flutter failed to read file at /tmp/flutter_tools.XXX/web_entrypoint.dart.
      PathNotFoundException ... errno 2"
    [Error] Process flutter/bin/flutter terminated! 1
    [Error] Widget Preview server process terminated

Flutter Doctor output

Doctor output
  └ [!] Flutter (Channel stable, 3.47.2, on Ubuntu 26.04 LTS 7.0.0-30-generic, locale en_US) [25ms]
        • Flutter version 3.47.2 on channel stable at /home/ubuntu/flutter
        ! Warning: `dart` on your path resolves to /usr/lib/dart/bin/dart, which is not inside your current Flutter SDK checkout at /home/ubuntu/flutter. Consider adding /home/ubuntu/flutter/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision d3b14c8769 (13 days ago), 2026-08-26 16:07:51 -0700
        • Engine revision a804b26164
        • Dart version 3.13.2
        • 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
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

    [✗] Android toolchain - develop for Android devices [20ms]
        ✗ Unable to locate Android SDK.
          Install Android Studio from: https://developer.android.com/studio/index.html
          On first launch it will assist you in installing the Android SDK components.
          (or visit https://flutter.dev/to/linux-android-setup for detailed instructions).
          If the Android SDK has been installed to a custom location, please use
          `flutter config --android-sdk` to update to that location.


    [✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) [8ms]
        ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

    [✗] Linux toolchain - develop for Linux desktop [24ms]
        ✗ clang++ is required for Linux development.
          It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
        ✗ CMake is required for Linux development.
          It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
        ✗ ninja is required for Linux development.
          It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
        ✗ pkg-config is required for Linux development.
          It is likely available from your distribution (e.g.: apt install pkg-config), or can be downloaded from https://www.freedesktop.org/wiki/Software/pkg-config/

    [✓] Connected device (1 available) [25ms]
        • Linux (desktop) • linux • linux-x64 • Ubuntu 26.04 LTS 7.0.0-30-generic

    [✓] Network resources [208ms]
        • All expected network resources are available.

    ! Doctor found issues in 4 categories.

Activity

  1. DanTup commented on Sep 8, 2026

    @DanTup
    ContributorAuthor

    @bkonyi oh, I also noticed:

        [Info] "Triggering reload..." x3 (all in the same second)
        [error] "Flutter failed to read file at /tmp/flutter_tools.XXX/web_entrypoint.dart.
          PathNotFoundException ... errno 2"
    

    (this was an AI summary of my log...)

    I wonder if this is part of the cause (and whether it's related at all to the stream sub issue). I'll try add some more logging around this code and see if I can figure out what's going on - but it's possible it'll be obvious to you as you're more familiar with this code :-)

  2. DanTup commented on Sep 8, 2026

    @DanTup
    ContributorAuthor

    According to AI, my multiple reloads was because I was logging the widget-preview output into the project folder, and it was seeing that file being modified and generating output (which was then written to the log file, which repeated the cycle, and triggering rebuilds along the way).

    I'll try moving my log file outside of the project for future testing, although it's not clear to me why that lead to a crash (unless there is some race if builds are triggered repeatedly?)

  3. added
    in triagePresently being triaged by the triage team
    toolAffects the "flutter" command-line tool. See also t: labels.
    team-toolOwned by Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 9, 2026
  4. puneetkukreja98 commented on Sep 9, 2026

    @puneetkukreja98
    Contributor

    @DanTup Thanks for reporting the issue, routing this to team-tool for further investigation.

    Simliar issue:
    #187322

  5. added
    P2Important issues not at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    a: widget previewsIssues related to the Widget Previewer tooling
    on Sep 18, 2026
  6. self-assigned this
    on Sep 18, 2026
  7. DanTup commented on Oct 1, 2026

    @DanTup
    ContributorAuthor

    @bkonyi re-opening this as the fix PR for this was reverted (#193637)

    The reason for revert was failing tests, described here: #192930 (comment)

    Bad state: Cannot add new events after calling close
    #0      _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:256:24)
    #1      AnalysisServer._handleProgress (package:flutter_tools/src/dart/analysis.dart:304:30)
    #2      AnalysisServer._handleServerResponse (package:flutter_tools/src/dart/analysis.dart:272:15)
    #3      AnalysisServer._handleServerResponseRaw (package:flutter_tools/src/dart/analysis.dart:226:7)
    #4      Zone.runUnaryGuarded (dart:async/zone.dart:486:14)
    
  8. reopened this on Oct 1, 2026
  9. github-actions commented on Oct 17, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: widget previewsIssues related to the Widget Previewer toolingteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions