dio icon indicating copy to clipboard operation
dio copied to clipboard

A lot of connection errors when send requests in Timer.periodic

Open justjew opened this issue 3 years ago • 1 comments

I need to send a POST request every minute. So I use Timer.periodic for it. In debug mode there is no problem. But in production there are hundreds of: SocketException: Failed host lookup Connecting timed out [0ms] SocketException: Software caused connection abort SocketException: Bad file descriptor HandshakeException: Connection terminated during handshake

I see them in Sentry. I am absolutely sure there was no problems with internet connection. Besides, half of requests reach the destination.

void _startSendingDeviceActivity() {
  _sendDeviceActiviryTimer?.cancel();
  _sendDeviceActivity();
  _sendDeviceActiviryTimer = Timer.periodic(const Duration(minutes: 1), _sendDeviceActivity);
}

Future<void> _sendDeviceActivity([_]) async {
  final DeviceInfo deviceInfo = await DeviceActivity.getDeviceInfo();
  _userApi.sendDeviceActivity(deviceInfo);
}

@override
void dispose() {
  _sendDeviceActiviryTimer?.cancel();
  super.dispose();
}

New Issue Checklist

  • [x] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name flutter
Platform Version 2.10.5
Dio Version 4.0.6
Android Studio / Xcode Version Android Studio 2021.1.1 patch 2 / Xcode 13.2.1
Repro rate sometimes ~50%
Repro with our demo prj idk
Demo project link -

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

justjew avatar May 21 '22 14:05 justjew

Any answer?

justjew avatar Jul 21 '22 12:07 justjew

Hi @justjew , we have the same problem. Do you have any update regarding this?

Habil24 avatar Jan 30 '23 13:01 Habil24

Same question here

hbock-42 avatar Mar 14 '23 16:03 hbock-42