Skip to content

Conversation

@koji-1009
Copy link
Contributor

@koji-1009 koji-1009 commented Nov 4, 2025

fix #2457

Description

Implements timeout handling for NativeAdapter. Previously, Dio's timeout options (sendTimeout, connectTimeout, receiveTimeout) were ignored when using NativeAdapter.

This PR adds proper timeout features in ConversionLayerAdapter, following the same approach as io_adapter.dart.

Note: Due to http package limitations, connectTimeout and receiveTimeout are combined for the response phase.

New Pull Request Checklist

  • I have read the Documentation
  • I have searched for a similar pull request in the project and found none
  • I have updated this branch with the latest main branch to avoid conflicts (via merge from master or rebase)
  • I have added the required tests to prove the fix/feature I'm adding
  • I have updated the documentation (if necessary)
  • I have run the tests without failures
  • I have updated the CHANGELOG.md in the corresponding package

Additional context and info (if any)

@koji-1009 koji-1009 requested a review from a team as a code owner November 4, 2025 11:46
@koji-1009 koji-1009 force-pushed the feat/timeout_native_adapter branch from cf0f7d6 to fdcda84 Compare November 4, 2025 11:53
@koji-1009 koji-1009 marked this pull request as draft November 4, 2025 12:00
@koji-1009 koji-1009 force-pushed the feat/timeout_native_adapter branch from fdcda84 to bc6c463 Compare November 4, 2025 12:14
@koji-1009 koji-1009 marked this pull request as ready for review November 4, 2025 12:21
Comment on lines +54 to +58
// http package doesn't separate connect and receive phases,
// so we combine both timeouts for client.send()
final connectTimeout = options.connectTimeout ?? Duration.zero;
final receiveTimeout = options.receiveTimeout ?? Duration.zero;
final totalTimeout = connectTimeout + receiveTimeout;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, it might be good to exclude connectionTimeout from support.

Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping fix the behavior!

Future<void>? cancelFuture,
) async {
final request = await _fromOptionsAndStream(
final timeoutCompleter = Completer<void>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all onTimeout throws DioException, is the completer still valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's required. The completer is used to trigger the AbortableRequest's cancellation logic. The throw just handles reporting the error to the caller. We must signal the cancellation first, then throw.

Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The CI seems failing because of some request issues (not sure if it's related but it looks like not). Could you help to investigate?

@koji-1009
Copy link
Contributor Author

Looking at https://github.com/cfug/dio/actions/workflows/tests.yml, it seems tests are failing in other PRs as well. I'll look into it. Thanks for maintaining dio and related packages.

@koji-1009
Copy link
Contributor Author

https://httpbun.com/bytes/ no longer accepts values greater than 90, causing some tests to fail.

$ curl https://httpbun.com/bytes/5000
Size can't be greater than 90%

$ curl https://httpbun.com/bytes/89
�0]$)bR]

Q�)����u�Z��Rؼ�V�PEIY2A��!�Œ��X���7���Cr	R�[w�zt��0@�e&��lv�&G%

sharat87/httpbun@eade3e2

@koji-1009
Copy link
Contributor Author

#2460

I created a pull request to fix the test case.
CI is successful in my personal Git repository.
https://github.com/koji-1009/dio/actions/runs/19401146603

@github-actions
Copy link
Contributor

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart 🟢 92.5% 🟢 94.74% 🟢 2.24%
Overall Coverage 🟢 85.59% 🟢 85.72% 🟢 0.13%

Minimum allowed coverage is 0%, this run produced 85.72%

@AlexV525 AlexV525 merged commit c53d0b3 into cfug:main Nov 17, 2025
3 checks passed
@koji-1009
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[native_dio_adapter] NativeAdapter ignores timeout options (sendTimeout, connectTimeout, receiveTimeout)

2 participants