0

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?

user13595734
  • 51
  • 2
  • 6
  • Were you able to resolve this issue? If so then what was the problem? I have exactly the same behaviour in a .net 6 api. Client calling the api crashes with connection reset but server receives the request and continues without problem. – user923256 Oct 08 '22 at 15:32
  • @user923256 unfortunately not. I contacted Heroku support twice and provided them with all of the details, but they kept stating that it’s a client-side issue and has nothing to do with their servers. I was not able to find the problem in the mobile app, though. If you manage to fix it somehow, please let me know. – user13595734 Oct 09 '22 at 17:12

0 Answers0