Bug:HttpException: Connection closed before full header was received
Package
dio
Version
5.7.0
Operating-System
Windows
Adapter
Default Dio
Output of flutter doctor -v
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [版本 10.0.26100.4061], locale zh-CN) [622ms]
• Flutter version 3.29.0 on channel stable at D:\Flutter\Android\flutter-sdk\flutter_windows_3.29.0-stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 35c388afb5 (4 months ago), 2025-02-10 12:48:41 -0800
• Engine revision f73bfc4522
• Dart version 3.7.0
• DevTools version 2.42.2
[√] Windows Version (Windows 11 or higher, 24H2, 2009) [2.9s]
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [3.8s]
• Android SDK at D:\Flutter\Android\android-sdk
• Platform android-36, build-tools 35.0.1
• ANDROID_HOME = D:\Flutter\Android\android-sdk
• Java binary at: D:\Flutter\Android\android-studio-narwhal-canary10\jbr\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.6+-13391695-b895.109)
• All Android licenses accepted.
[√] Chrome - develop for the web [171ms]
• Chrome at C:\Users\Flutter\AppData\Local\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.13.7) [170ms]
• Visual Studio at D:\Flutter\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.13.36105.23
• Windows 10 SDK version 10.0.22621.0
[√] Android Studio (version 2024.3.2) [29ms]
• Android Studio at D:\Flutter\Android\android-studio-meerkat-feature-drop-canary3
• 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.5+-12932927-b750.29)
[√] Android Studio (version 2025.1.1) [27ms]
• Android Studio at D:\Flutter\Android\android-studio-narwhal-canary10
• 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+-13391695-b895.109)
[√] Connected device (3 available) [197ms]
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 10.0.26100.4061]
• Chrome (web) • chrome • web-javascript • Google Chrome 136.0.7103.93
• Edge (web) • edge • web-javascript • Microsoft Edge 136.0.3240.92
[√] Network resources [607ms]
• All expected network resources are available.
• No issues found!
Dart Version
3.7.0
Steps to Reproduce
首先,感谢杜文及CFUG各位成员的贡献。 我看这个Bug出现了很长时间,但是都没有得到解决,期望这个问题得到解决。
我查看了已有Issues,也没看到好的解决方案 https://github.com/cfug/dio/issues?q=is%3Aissue%20state%3Aclosed%20HttpException%3A%20Connection%20closed%20before%20full%20header%20was%20received
重现场景:我的应用类似应用宝多任务下载文件,同时执行多个下载任务时,会出现这个报错:HttpException: Connection closed before full header was received,从而导致下载失败。
我这打印出来的报错是这样:DioExceptionType.unknown HttpException: Connection closed before full header was received
Expected Result
正常下载,不会报错导致下载失败
Actual Result
报错:HttpException: Connection closed before full header was received,然后下载失败
I am experiencing a similar issue, but with a much higher frequency. The Crashlytics dashboard has recorded over 75,000 occurrences related to this problem.
Output of flutter doctor -v
[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [Version 10.0.26100.4351], locale en-US) [462ms]
• Flutter version 3.29.3 on channel stable at C:\Users\pdong\dev\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ea121f8859 (3 months ago), 2025-04-11 19:10:07 +0000
• Engine revision cf56914b32
• Dart version 3.7.2
• DevTools version 2.42.3
[√] Windows Version (Windows 11 or higher, 24H2, 2009) [2.2s]
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [5.5s]
• Android SDK at C:\Users\pdong\AppData\Local\Android\sdk
• Platform android-35, build-tools 35.0.1
• Java binary at: C:\Users\pdong\AppData\Local\Programs\Android Studio\jbr\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.6+-13368085-b895.109)
• All Android licenses accepted.
[√] Chrome - develop for the web [163ms]
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.14.0 Preview 3.0) [162ms]
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Preview
• Visual Studio Professional 2022 version 17.14.36015.10
• The current Visual Studio installation is a pre-release version. It may not be supported by Flutter yet.
• Windows 10 SDK version 10.0.26100.0
[√] Android Studio (version 2024.3.2) [20ms]
• Android Studio at C:\Users\pdong\AppData\Local\Programs\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+-13368085-b895.109)
[√] VS Code (version 1.101.0) [18ms]
• VS Code at C:\Users\pdong\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.112.0
[√] Connected device (4 available) [269ms]
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26100.4351]
• Chrome (web) • chrome • web-javascript • Google Chrome 138.0.7204.51
• Edge (web) • edge • web-javascript • Microsoft Edge 138.0.3351.65
[√] Network resources [1,352ms]
• All expected network resources are available.
• No issues found!
Any solution for this????