Skip to content

Dio().fetch() hangs in isolate #2399

@mikes222

Description

@mikes222

Package

dio

Version

5.8.0+1

Operating-System

Windows

Adapter

Default Dio

Output of flutter doctor -v

[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [Version 10.0.22631.5189], locale de-AT) [361ms]
    • Flutter version 3.29.3 on channel stable at C:\develop\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ea121f8859 (3 weeks ago), 2025-04-11 19:10:07 +0000
    • Engine revision cf56914b32
    • Dart version 3.7.2
    • DevTools version 2.42.3

[√] Windows Version (11 Pro 64-bit, 23H2, 2009) [2,7s]

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [283ms]
    • Android SDK at C:\Users\micro\AppData\Local\Android\sdk
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/windows-android-setup for more details.

[√] Chrome - develop for the web [143ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.2) [142ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.8.34322.80
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.3) [13ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13355223-b631.42)

[√] Connected device (4 available) [214ms]
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 15 (API 35) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22631.5189]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 135.0.7049.115
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 136.0.3240.50

[√] Network resources [656ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.
P

Dart Version

Dart SDK version: 3.7.2 (stable) (Tue Mar 11 04:27:50 2025 -0700) on "windows_x64"

Steps to Reproduce

I have created a method to fetch data from http(s) server. When calling this method in the main thread everything works. Unfortunately if I call the very same method in an isolate the last line in the following code snippet Response response = await responseFuture; hangs indefinitely. I am unable to debug what exactly causes this problem and therefore would like to get some hints how to find the root cause.

RequestOptions requestOptions = RequestOptions(
  path: source,
  method: "GET",
  connectTimeout: const Duration(seconds: 35),
  receiveTimeout: const Duration(seconds: 40),
  sendTimeout: const Duration(seconds: 62),
  //receiveDataWhenStatusError: true,
  followRedirects: true,
  responseType: ResponseType.stream,
);

final Dio _httpClient = Dio();

print("vor response");
Future<Response> responseFuture = _httpClient.fetch(requestOptions);
Response response = await responseFuture;

Expected Result

Not hanging in an isolate created with Isolate.spawn

Actual Result

hanging when awaiting the result in the isolate

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions