gpt4 book ai didi

angularjs - 如何在浏览器中忽略来自 AWS ELB 的空闲超时

转载 作者:行者123 更新时间:2023-12-04 18:56:33 33 4
gpt4 key购买 nike

我有一个应用程序,用户可以在其中使用 angular-file-upload.js 上传 PDF

此库不支持文件分块:https://github.com/nervgh/angular-file-upload/issues/41

我的弹性负载平衡器被配置为有 10 秒的空闲超时,应用程序的其他部分依赖于保持这个参数。

问题是,如果文件上传时间超过 10 秒,用户会在浏览器中收到 504 网关超时和错误消息。但是,该文件仍会在一段时间后到达服务器。

如何忽略或不向用户显示来自 ELB 的 504 网关超时?有没有其他方法可以解决这个问题?

最佳答案

您遇到的问题是 ELB 总是会关闭连接,除非它从您的服务器获取一些流量。请参阅以下来自 AWS docs .对于 ALB 或经典负载均衡器来说,这是相同的行为。

By default, Elastic Load Balancing sets the idle timeout to 60 seconds for both connections. Therefore, if the instance doesn't send some data at least every 60 seconds while the request is in flight, the load balancer can close the connection. To ensure that lengthy operations such as file uploads have time to complete, send at least 1 byte of data before each idle timeout period elapses, and increase the length of the idle timeout period as needed.



因此,要解决此问题,您有两种选择:
  • 更改服务器处理以在连接建立后立即开始发送一些数据,间隔小于 10 秒。
  • 使用另一个库进行上传,或使用 vanilla javascript。那里有很多例子,例如this one .

  • 编辑:第三个选项
    感谢@colde 提出有效的观点,即您可以简单地完全解决您的负载均衡器。这具有释放与冗长上传相关的服务器资源的额外好处。在我们的实现中,我们使用了 pre-signed urls以安全地实现这一目标。

    关于angularjs - 如何在浏览器中忽略来自 AWS ELB 的空闲超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51363290/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com