Repository navigation
Description
Package
dio
Version
5.4.2+1
Operating-System
Android, iOS
Adapter
Default Dio
Output of flutter doctor -v
[✓] Flutter (Channel stable, 3.19.4, on macOS 14.4.1 23E224 darwin-arm64, locale en-EG)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.87.2)
[✓] Connected device (3 available)
! Error: Browsing on the local area network for Me. Ensure the device is unlocked and attached with a cable or associated with the same
local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for Mohamed’s Iphone (2). Ensure the device is unlocked and attached with a cable or
associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for iPhone Fadwa. Ensure the device is unlocked and attached with a cable or associated
with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for H. Sayed. Ensure the device is unlocked and attached with a cable or associated with the
same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources
• No issues found!Dart Version
3.3.2
Steps to Reproduce
- Run with any version of Dio above 5.4.0.
- try to send more requests in a short period of time.
Expected Result
When using Dio version 5.4.0, the connection is not closed and the response succeeds.
Actual Result
flutter: The following exception was thrown getBOKRechargeRequestStatusProvider:
flutter: AppException.serverException(type: ServerExceptionType.unknown, message: HttpException: Connection closed before response was received, uri = https://api.bravo-sudan.com/bravo/api/v1/bok/getRechargeRequests, code: null)
flutter:
#0 DioMixin.fetch (package:dio/src/dio_mixin.dart:509:7)
#1 MainApiFacade._errorHandler (package:bravo/core/infrastructure/network/main_api/api_callers/main_api_facade.dart:66:14)
#2 TransactionRemoteDataSource.getBOKRechargeRequestStatus (package:bravo/features/transaction/infrastructure/data_sourse/transaction_remote_remote_data_source.dart:48:20)
#3 TransactionHistoryRepository.getBOKRechargeRequestStatus (package:bravo/features/transaction/infrastructure/repository/transaction_history_repository.dart:43:20)


Activity
AlexV525 commentedon Mar 28, 2024
If this is version specific, could you run
git bisectto find out which commit breaks the functionality?Abouassi98 commentedon Mar 28, 2024
I have recently upgraded Dio from version 5.4.0 to 5.4.2+1. However, I believe the issue began with version 5.4.1.
AlexV525 commentedon Mar 28, 2024
Running bisect will help to determine which exact commit breaks the behavior.
Abouassi98 commentedon Mar 28, 2024
I am contemplating running a bisect to pinpoint the problematic commit. However, I want to clarify that my recent commit solely consisted of upgrading the version to 5.4.2+1. Additionally, I have already tested version 5.4.1, as I suspect the issue originated there, and encountered the same problem.
AlexV525 commentedon Mar 28, 2024
I understand your statement clearly, IMO. I'm asking you to do the bisect because you have a reproducible example and can debug the issue easily. Besides, simply switching between versions might not be helpful since every version includes a bunch of commits.
Abouassi98 commentedon Mar 28, 2024
I've completed running
git bisectto identify the commit that introduced the issue in the Dio package. After testing multiple commits, I've found that the first bad bisect commit is "Fix streamed response cancellation and progress (#2068)".845e06f
AlexV525 commentedon Mar 29, 2024
Thanks for the bisect! Now could you split a minimal reproducible example so we can take a deeper investigation with your case?
AlexV525 commentedon Mar 29, 2024
cc @kuhnroyal to check the implementation as the code owner
6 remaining items
EArminjon commentedon Apr 5, 2024
What is the recommandation to avoid this issue ?
kuhnroyal commentedon Apr 5, 2024
This was changed in 5.4.1, you might be able to lock the dio version to 5.4.0.
devguusta commentedon Apr 8, 2024
wratheus commentedon Apr 10, 2024
The issue occurs when you have two requests with different CancelTokens, and when the first request is completed, the second request starts executing. At that moment, if you cancel the CancelToken of the first request somewhere in the code (for example, in Bloc dispose), then the second request gets canceled before it is received, even if it had a different cancelToken from the first request, causing the entire DIO connection to close.
For example
While request2 is still being execute, a cancelation occurs on the first CancelToken in parallel in code, which will drop request2. that cancelation should not influence second request.
Fixes I found so far:
kuhnroyal commentedon Apr 10, 2024
@wratheus Can you reproduce this in a test case? Also not sure if this is the same issue.
This seems to work:
AlexV525 commentedon Apr 11, 2024
This case fails.
dio/dio_test/lib/src/test/cancellation_tests.dart
Lines 117 to 143 in 537832e
wratheus commentedon Apr 11, 2024
There is no difference if there is cancelToken in second request or no. Same with post requests. That's the problem I was talking about. Issue does not occurs at 5.3.3 version
🔥 Do not detaches sockets / terminates client stream (#2173)
chesongsong commentedon Jun 24, 2024
Is there a big difference between 5.4.0 and 5.4.2+1? I also reproduced this problem on 5.4.2+1. If I lock 5.4.0, does my user need to make API level adjustments?
AlexV525 commentedon Jun 24, 2024
The fix is included in v5.4.3 and shall not require interface updates.
🔥 Do not detaches sockets / terminates client stream (cfug#2173)