Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当频繁出现连接和读取异常时,socket句柄无法正常释放 #2109

Closed
LiXianYua opened this issue Feb 4, 2024 · 2 comments
Closed

Comments

@LiXianYua
Copy link

LiXianYua commented Feb 4, 2024

Package

dio

Version

5.2.0+1

Operating-System

Android

Output of flutter doctor -v

[✓] Flutter (Channel stable, 3.10.6, on macOS 14.1.1 23B81 darwin-arm64, locale zh-Hans-CN)
    • Flutter version 3.10.6 on channel stable at /Users/xxx/fvm/versions/3.10.6
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (7 months ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1
    • 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 (Android SDK version 34.0.0)
    • Android SDK at /Users/xx/Dev/Sdk/Android
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /usr/bin/java
    • Java version Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

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

[!] Android Studio (version 2023.1)
    • Android Studio at /Users/xxx/Applications/Android Studio Hedgehog 2023.1.1 Patch 2.app/Contents
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio
    • Android Studio at /Users/xxx/Applications/Android Studio.app/Contents
    • 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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.3)
    • IntelliJ at /Users/xxx/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 77.3.1
    • Dart plugin version 233.13763.5

[✓] VS Code (version 1.85.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (3 available)
    • Nexus 4 (mobile) • 2c80994a007f5312 • android-arm    • Android null (API null)
    • macOS (desktop)  • macos            • darwin-arm64   • macOS 14.1.1 23B81 darwin-arm64
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 121.0.6167.139

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

! Doctor found issues in 2 categories.

Dart Version

3.0.6

Steps to Reproduce

弱网环境下,两个Dio实例,频繁请求(重试),从二月一日到二月三日,共请求6297次,前6296次都是连接超时和读取超时,第6297次出现 OS Error: Too many open files, errno = 24 ,查看/proc/$(pid)/fd/发现进程下有一百多个socket句柄持续存在无法释放,后续出现App卡死,无法操作
dio实例创建如下
`class WeatherRepository {
factory WeatherRepository() => _instance ??= WeatherRepository.initData();

WeatherRepository.initData() {
_dio.interceptors.add(dio.LogInterceptor(requestBody: true, responseBody: true, logPrint: Logger.i));
_dio.options.baseUrl = 'https://$_domain';
}

static WeatherRepository? _instance;

final dio.Dio _dio = dio.Dio(BaseOptions(
connectTimeout: const Duration(seconds: 10),
receiveTimeout: const Duration(seconds: 10),
sendTimeout: const Duration(seconds: 10),
));

String get _domain => SystemController.to.commonDomain;

/// 。。。。。。 ////

}`

连接超时异常:
DioException [connection timeout]: The request connection took longer than 0:00:10.000000. It was aborted. DioMixin.fetch.<anonymous closure> (package:dio/src/dio_mixin.dart:533) _rootRunUnary (dart:async/zone.dart:1407) _CustomZone.runUnary (dart:async/zone.dart:1308) _FutureListener.handleError (dart:async/future_impl.dart:165) Future._propagateToListeners.handleError (dart:async/future_impl.dart:796) Future._propagateToListeners (dart:async/future_impl.dart:817) Future._completeError (dart:async/future_impl.dart:592) _SyncCompleter._completeError (dart:async/future_impl.dart:51) _Completer.completeError (dart:async/future_impl.dart:23) Future.any.onError (dart:async/future.dart:620) _rootRunBinary (dart:async/zone.dart:1423) _CustomZone.runBinary (dart:async/zone.dart:1315) _FutureListener.handleError (dart:async/future_impl.dart:162) Future._propagateToListeners.handleError (dart:async/future_impl.dart:796) Future._propagateToListeners (dart:async/future_impl.dart:817) Future._completeError (dart:async/future_impl.dart:592) Future._chainForeignFuture.<anonymous closure> (dart:async/future_impl.dart:537) _rootRun (dart:async/zone.dart:1399) _CustomZone.run (dart:async/zone.dart:1301) _CustomZone.runGuarded (dart:async/zone.dart:1209) _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1249) _microtaskLoop (dart:async/schedule_microtask.dart:40) _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)

Too many open files异常:
Error: SocketException: Connection failed (OS Error: Too many open files, errno = 24), address = xxxxxxxxx, port = 443, DioMixin.fetch.<anonymous closure> (package:dio/src/dio_mixin.dart:533) _rootRunUnary (dart:async/zone.dart:1407) _CustomZone.runUnary (dart:async/zone.dart:1308) _FutureListener.handleError (dart:async/future_impl.dart:165) Future._propagateToListeners.handleError (dart:async/future_impl.dart:796) Future._propagateToListeners (dart:async/future_impl.dart:817) Future._completeError (dart:async/future_impl.dart:592) _SyncCompleter._completeError (dart:async/future_impl.dart:51) _Completer.completeError (dart:async/future_impl.dart:23) Future.any.onError (dart:async/future.dart:620) _rootRunBinary (dart:async/zone.dart:1423) _CustomZone.runBinary (dart:async/zone.dart:1315) _FutureListener.handleError (dart:async/future_impl.dart:162) Future._propagateToListeners.handleError (dart:async/future_impl.dart:796) Future._propagateToListeners (dart:async/future_impl.dart:817) Future._completeError (dart:async/future_impl.dart:592) Future._chainForeignFuture.<anonymous closure> (dart:async/future_impl.dart:537) _rootRun (dart:async/zone.dart:1399) _CustomZone.run (dart:async/zone.dart:1301) _CustomZone.runGuarded (dart:async/zone.dart:1209) _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1249) _microtaskLoop (dart:async/schedule_microtask.dart:40) _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)

Expected Result

句柄正常释放

Actual Result

句柄无法释放

@LiXianYua LiXianYua added h: need triage This issue needs to be categorized s: bug Something isn't working labels Feb 4, 2024
@AlexV525
Copy link
Member

AlexV525 commented Feb 4, 2024

请尝试 HttpClient 是否能复现相关情况。

@AlexV525 AlexV525 added the h: need more info Further information is requested label Feb 4, 2024
@LiXianYua
Copy link
Author

使用http包依旧会出现此问题,和dio无关

@AlexV525 AlexV525 added i: not related and removed h: need more info Further information is requested h: need triage This issue needs to be categorized s: bug Something isn't working labels Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants