HttpClient deadline and retry #46557
Labels
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
library-io
type-enhancement
A request for a change that isn't a bug
I am developing an app in Flutter which uses
dart:io:HttpClient
to make requests to an API. The API occasionally accepts TCP connections slowly, rejects connections, returns HTTP 503 responses, returns other HTTP 5xx responses, or resets active connections. This happens during deployments, load balancer config updates, network outages, server overloads, and intermittent errors. I need my app to work properly in these situations, retrying up to a deadline.When the API is slow to accept the TCP connection, HttpClient throws
TimeoutException
after 15 seconds. Some of my app's request deadlines are longer than 15 seconds. The app must calculate the timeout value from the deadline and the current time and set theHttpClient.connectionTimeout
field. This code belongs inside HttpClient. Let's add adeadline
parameter onHttpClient::openUrl
and other methods.Golang supports deadlines with
net/http/Request.WithContext
andcontext.WithDeadline
.Once Dart's HttpClient has a deadline to work with, it can perform retries and tolerate the myriad ways the network and server can fail. This will make Flutter apps more robust. It will provide good user experience for users. This is especially important for phone users who rely on unreliable mobile internet connections.
HttpClient slowly cleans up abandoned network requests. With deadlines, it can do aggressive cleanup. This will reduce app memory usage, data transfer, and battery consumption.
There are levels of retry capability:
Any of these would provide a welcome improvement in Flutter app robustness.
CC: @timsneath
The text was updated successfully, but these errors were encountered: