首页 > 解决方案 > Blazor 服务器端 - AWS 环境中频繁出现 504 错误

问题描述

通过 AWS Elastic Beanstalk 将 blazor 服务器端项目部署到 Amazon Web Services 环境后,网站经常出现我无法理解的断开连接。

这些断开连接不会在测试时发生在本地。

错误:

[2020-04-30T16:29:18.326Z] Error: Connection disconnected with error 'Error'.

Failed to load resource: the server responded with a status of 504 ()

导致 504 错误的请求具有如下标头:

Request URL: https://mywebserver/_blazor?id=UOPQELxzuEcaGbpNUQA01Q&_=1588264098305
Request Method: GET
Status Code: 504 
Remote Address: 3.11.236.203:443
Referrer Policy: no-referrer-when-downgrade
content-length: 550
content-type: text/html
date: Thu, 30 Apr 2020 16:29:20 GMT
server: awselb/2.0
status: 504
:authority: mywebserver
:method: GET
:path: /_blazor?id=UOPQELxzuEcaGbpNUQA01Q&_=1588264098305
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-GB,en-US;q=0.9,en;q=0.8
content-type: text/plain;charset=UTF-8
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
x-requested-with: XMLHttpRequest

此问题似乎与此处发布的 Github 问题非常相似,微软目前正在调查该问题,尽管此问题与 AWS 无关:https ://github.com/dotnet/aspnetcore/issues/19094

任何帮助将不胜感激!

标签: amazon-web-servicesblazorblazor-server-side

解决方案


我最终设法解决了这个问题。

显然这个问题是由使用 LongPolling 引起的。LongPolling 发出请求并在取消请求之前等待 100 秒。通过在我的 AWS 设置中将超时设置为大于弹性负载均衡器中的默认值 60 秒,断开连接停止。建议将 110 秒作为安全超时值。

我为感兴趣的人打开的 Asp.NET github 上的问题:https ://github.com/dotnet/aspnetcore/issues/21369


推荐阅读