在http 503之后使用golang的Heroku“连接关闭而没有响应”H13

问题描述

我真的在这里遇到了我不明白的事情,真的很想得到一些帮助!赞赏。

基本上,我有一个运行基本 Go 服务器的 Heroku 应用

    s := &http.Server{
        Addr: ":" + Port,Handler: handler
    }
    err := s.ListenAndServe()

我的应用程序的目标是对 Spotify API 执行经过身份验证的请求。为此,我必须登录,我使用了很棒的 go 客户端 (https://github.com/zmb3/spotify)。

当我创建用户时,似乎是因为 Spotify API 有点不稳定,它向我发送了 503。查看日志,我明白了

2021/03/09 22:51:47 Couldn't create token: oauth2: cannot fetch token: 503 Service Unavailable

这就是它变得棘手的地方,从那里开始崩溃和燃烧。然后我得到一个

Response: upstream connect error or disconnect/reset before headers. reset reason: connection termination

at=error code=H13 desc="Connection closed without response" method=GET path="/rooms/V59TPC" host=api.sharedspotify.com request_id=8fee4d42-b7ad-4f31-a601-d3771e029362 fwd="92.184.105.234" dyno=web.1 connect=0ms service=151ms status=503 bytes=0 protocol=https

Process exited with status 1

看看有关该主题的所有内容,我正在努力找到正确的解决方案,而这正是我需要帮助的地方。

阅读 Heroku 文档后,我看到 H13 是由

引起的

H13 - 连接关闭,没有响应

当您的 Web dyno 中的进程接受连接,然后关闭套接字而不向其写入任何内容时,将引发此错误

可能发生这种情况的一个示例是,Unicorn Web 服务器配置的超时时间短于 30 秒,并且在超时发生之前工作人员尚未处理请求。在这种情况下,Unicorn 在写入任何数据之前关闭连接,导致 H13。


所以我认为做的是将服务器超时更改为 30 秒以上,您怎么看?这是正确的解决方案吗?

    s := &http.Server{
        Addr: ":" + Port,Handler: handler,ReadTimeout:  60 * time.Second,WriteTimeout: 100 * time.Second,IdleTimeout:  1200 * time.Second,}
    err := s.ListenAndServe()

非常感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)