对peer的“连接重置”故障排除。

发布于 2025-02-13 03:35:49 字数 1042 浏览 0 评论 0原文

我有一个使用它的Web API(烧瓶)和一个移动应用程序(Xamarin.forms)。直到一周前,一切都很好几个月了。突然在尝试访问Web API时,移动应用客户端客户开始投掷“ peer Reset”。确切的例外消息是:

Read error: ssl=0xd6269d18: I/O error during system call, Connection reset by peer

它似乎是随机发生的 - 有时一切正常,有时效果不佳。

在客户端方面,请求使用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();
}

该服务器托管在Heroku上。即使客户抛出异常,Heroku日志也表明请求已正确处理(状态200)。 服务器的示例路由:

@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

我编写了一个简短的Python脚本,该脚本试图以移动应用程序的方式使用API​​,并且似乎没有出现问题。 我应该在哪里寻找解决方案?烧瓶服务器更有可能出现问题,还是移动应用程序的问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文