dio icon indicating copy to clipboard operation
dio copied to clipboard

fix connection timeout runtime

Open saharvx9 opened this issue 2 years ago • 5 comments

New Pull Request Checklist

  • [x] I have read the Documentation
  • [x] I have searched for a similar pull request in the project and found none
  • [x] I have updated this branch with the latest develop to avoid conflicts (via merge from master or rebase)
  • [x] I have added the required tests to prove the fix/feature I am adding
  • [x] I have updated the documentation (if necessary)
  • [x] I have run the tests and they pass

This merge request fixes / refers to the following issues: ...

Pull Request Description

Bug : when changing the connection timeout in run time ,its being ignore this cus by this lines : loot at the comment

 HttpClient _configHttpClient(Future? cancelFuture, int connectionTimeout) {
    var _connectionTimeout = connectionTimeout > 0
        ? Duration(milliseconds: connectionTimeout)
        : null;

    if (cancelFuture != null) {
      var _httpClient = HttpClient();
      _httpClient.userAgent = null;
      if (onHttpClientCreate != null) {
        //user can return a HttpClient instance
        _httpClient = onHttpClientCreate!(_httpClient) ?? _httpClient;
      }
      _httpClient.idleTimeout = Duration(seconds: 0);
      cancelFuture.whenComplete(() {
        Future.delayed(Duration(seconds: 0)).then((e) {
          try {
            _httpClient.close(force: true);
          } catch (e) {
            //...
          }
        });
      });
      return _httpClient..connectionTimeout = _connectionTimeout;
    }
    if (_defaultHttpClient == null) {
      _defaultHttpClient = HttpClient();
      _defaultHttpClient!.idleTimeout = Duration(seconds: 3);
      if (onHttpClientCreate != null) {
        //user can return a HttpClient instance
        _defaultHttpClient =
            onHttpClientCreate!(_defaultHttpClient!) ?? _defaultHttpClient;
      }
      _defaultHttpClient!.connectionTimeout = _connectionTimeout; // --> this line never calls when changing timeout connection
    }
    return _defaultHttpClient!;
  }

so i remove this line and set the new connection timeout in the return

saharvx9 avatar Jun 27 '22 13:06 saharvx9

good catch, and hope it will be merged soon!

vigdora avatar Jun 29 '22 11:06 vigdora

Beautiful solution which also includes unit test! Can you please expedite this one?

amitBlueVine avatar Jun 29 '22 13:06 amitBlueVine

been waiting for this one - nicely done!!

hilazan avatar Jun 29 '22 14:06 hilazan

When plan to release this fix?

MingSern avatar Sep 09 '22 01:09 MingSern

I'm using my own fork because of this issue and lack of PR being released. Disappointing :-(

gslender avatar Sep 09 '22 01:09 gslender