I have a web api (Flask) and a mobile app (Xamarin.Forms) that uses it. Everything had been working well for a few months until a week ago. Suddenly mobile app clients started throwing "Connection reset by peer" when trying to access the web api. The exact exception message is:
Read error: ssl=0xd6269d18: I/O error during system call, Connection reset by peer
It seems to happen randomly - sometimes everything works well, sometimes not.
On the clients' side, requests are made using the System.Net.Http.HttpClient
:
public async Task<string> GetClientData(string token)
{
HttpResponseMessage response =
await httpClient.GetAsync(server_url + Resx.Urls.get_route + "?token=" + token);
return await response.Content.ReadAsStringAsync();
}
The server is hosted on Heroku. Even when clients throw exceptions, the Heroku logs show that the requests were correctly handled (status 200). An example route of my server:
@app.route('/get', methods=['GET'])
def get():
clients = get_users() # database call
token = request.args.get('token')
for c in clients:
if(c.token == token):
return c.to_json()
abort(400) # no client with such token
I wrote a short python script that tries to use the api the same way my mobile app does, and it seems that the problem does not occur there. Where should I look for the solution? Is it more likely that something is wrong with the Flask server, or is it a problem with the mobile app?