postgresql - Heroku Go WebApp 错误 - 连接关闭而没有响应

标签 postgresql http go heroku

我正在尝试在 Heroku 中部署一个 Golang 应用程序。我收到 H13 错误,不知道如何解决。

该应用程序查询数据库并返回结果表。数据库小,查询小。它在8080端口本地运行,完全没有问题。

H13 Error documentation

This error is thrown when a process in your web dyno accepts a connection, but then closes the socket without writing anything to it.

One example where this might happen is when a Unicorn web server is configured with a timeout shorter than 30s and a request has not been processed by a worker before the timeout happens. In this case, Unicorn closes the connection before any data is written, resulting in an H13.



据我所知,我没有运行 Unicorn Web 服务器(尽管我不得不首先配置服务器,这超出了我的舒适区)。我正在从 vanilla net/http 运行应用程序包 - 没有路由附加组件或类似的东西。我做了一些谷歌搜索并尝试延长超时时间,如下所示:

s := &http.Server{
    Addr: ":8080",
    ReadTimeout:  5 * time.Second,
    WriteTimeout: 10 * time.Second,
    IdleTimeout:  120 * time.Second,
}


if  len(os.Getenv("PORT")) > 0 {
    s := &http.Server{
        Addr: ":" + os.Getenv("PORT"),
        ReadTimeout:  50 * time.Second,
        WriteTimeout: 100 * time.Second,
        IdleTimeout:  1200 * time.Second,
    }
    log.Fatal(s.ListenAndServe())
        } 

log.Fatal(s.ListenAndServe())
ListenAndServe()通常在 http 上调用目的。在这里,我创建了一个服务器对象,并给它大量延长超时,然后调用 ListenAndServe()在这方面,但我没有取得任何进展。一样H13一直出错。

这些是错误日志:
2020-01-06T18:46:20.771328+00:00 heroku[web.1]: Unidling
2020-01-06T18:46:20.776052+00:00 heroku[web.1]: State changed from down to starting
2020-01-06T18:46:21.616792+00:00 heroku[web.1]: Starting process with command `bin/gowebappdatabase`
2020-01-06T18:46:24.357786+00:00 heroku[web.1]: State changed from starting to up
2020-01-06T18:46:24.284251+00:00 app[web.1]: Incipio - I begin.
2020-01-06T18:46:25.826969+00:00 app[web.1]: 2020/01/06 18:46:25 http: panic serving 10.71.246.139:27839: dial tcp: lookup port=0: no such host
2020-01-06T18:46:25.827017+00:00 app[web.1]: goroutine 20 [running]:
2020-01-06T18:46:25.827020+00:00 app[web.1]: net/http.(*conn).serve.func1(0xc0001100a0)
2020-01-06T18:46:25.827022+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:1769 +0x139
2020-01-06T18:46:25.827024+00:00 app[web.1]: panic(0x7e4280, 0xc00010e320)
2020-01-06T18:46:25.827026+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/runtime/panic.go:522 +0x1b5
2020-01-06T18:46:25.827028+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/dbconnect.runQuery(0xc000150160, 0x150, 0x0)
2020-01-06T18:46:25.827031+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/dbconnect/connectdb.go:78 +0xff
2020-01-06T18:46:25.827033+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/dbconnect.PointsGdTableQuery(0xc000150160, 0x150, 0x0, 0x0, 0x0)
2020-01-06T18:46:25.827035+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/dbconnect/connectdb.go:161 +0x64
2020-01-06T18:46:25.827037+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/routing.ServeHome(0x8db260, 0xc00013a000, 0xc000124100)
2020-01-06T18:46:25.827039+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/routing/routing.go:35 +0x1b5
2020-01-06T18:46:25.827041+00:00 app[web.1]: net/http.HandlerFunc.ServeHTTP(0x863ca0, 0x8db260, 0xc00013a000, 0xc000124100)
2020-01-06T18:46:25.827043+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:1995 +0x44
2020-01-06T18:46:25.827045+00:00 app[web.1]: net/http.(*ServeMux).ServeHTTP(0xba17c0, 0x8db260, 0xc00013a000, 0xc000124100)
2020-01-06T18:46:25.827047+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:2375 +0x1d6
2020-01-06T18:46:25.827049+00:00 app[web.1]: net/http.serverHandler.ServeHTTP(0xc000086c30, 0x8db260, 0xc00013a000, 0xc000124100)
2020-01-06T18:46:25.827051+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:2774 +0xa8
2020-01-06T18:46:25.827053+00:00 app[web.1]: net/http.(*conn).serve(0xc0001100a0, 0x8dbc20, 0xc000118180)
2020-01-06T18:46:25.827055+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:1878 +0x851
2020-01-06T18:46:25.827056+00:00 app[web.1]: created by net/http.(*Server).Serve
2020-01-06T18:46:25.827058+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:2884 +0x2f4
2020-01-06T18:46:25.828262+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=gowebappdatabase.herokuapp.com request_id=b57f171c-5a63-4f2b-b54c-444d7c46d871 fwd="176.61.86.66" dyno=web.1 connect=1ms service=6ms status=503 bytes=0 protocol=https
2020-01-06T18:46:26.697559+00:00 app[web.1]: 2020/01/06 18:46:26 http: panic serving 10.67.225.150:14843: dial tcp: lookup port=0: no such host
2020-01-06T18:46:26.697582+00:00 app[web.1]: goroutine 7 [running]:
2020-01-06T18:46:26.697585+00:00 app[web.1]: net/http.(*conn).serve.func1(0xc00008d180)
2020-01-06T18:46:26.697588+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:1769 +0x139
2020-01-06T18:46:26.697590+00:00 app[web.1]: panic(0x7e4280, 0xc00008a320)
2020-01-06T18:46:26.697592+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/runtime/panic.go:522 +0x1b5
2020-01-06T18:46:26.697595+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/dbconnect.runQuery(0xc0000946e0, 0x150, 0x0)
2020-01-06T18:46:26.697597+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/dbconnect/connectdb.go:78 +0xff
2020-01-06T18:46:26.697599+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/dbconnect.PointsGdTableQuery(0xc0000946e0, 0x150, 0x0, 0x0, 0x0)
2020-01-06T18:46:26.697601+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/dbconnect/connectdb.go:161 +0x64
2020-01-06T18:46:26.697604+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/routing.ServeHome(0x8db260, 0xc0001b2000, 0xc000128100)
2020-01-06T18:46:26.697606+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/routing/routing.go:35 +0x1b5
2020-01-06T18:46:26.697608+00:00 app[web.1]: net/http.HandlerFunc.ServeHTTP(0x863ca0, 0x8db260, 0xc0001b2000, 0xc000128100)
2020-01-06T18:46:26.697611+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:1995 +0x44
2020-01-06T18:46:26.697614+00:00 app[web.1]: net/http.(*ServeMux).ServeHTTP(0xba17c0, 0x8db260, 0xc0001b2000, 0xc000128100)
2020-01-06T18:46:26.697616+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:2375 +0x1d6
2020-01-06T18:46:26.697618+00:00 app[web.1]: net/http.serverHandler.ServeHTTP(0xc000086c30, 0x8db260, 0xc0001b2000, 0xc000128100)
2020-01-06T18:46:26.697620+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:2774 +0xa8
2020-01-06T18:46:26.697622+00:00 app[web.1]: net/http.(*conn).serve(0xc00008d180, 0x8dbc20, 0xc0000206c0)
2020-01-06T18:46:26.697625+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:1878 +0x851
2020-01-06T18:46:26.697627+00:00 app[web.1]: created by net/http.(*Server).Serve
2020-01-06T18:46:26.697629+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/net/http/server.go:2884 +0x2f4
2020-01-06T18:46:26.697828+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/favicon.ico" host=gowebappdatabase.herokuapp.com request_id=088bcdd0-e16f-40f9-a6a0-8d61f4bb5beb fwd="176.61.86.66" dyno=web.1 connect=5ms service=3ms status=503 bytes=0 protocol=https

我很想能够解决这个问题。一整年都让我头疼。

最佳答案

您发布的代码不正确:
s.ListenAndServe()阻塞当前的 goroutine。

第二s.ListenAndServe()永远不会在您的代码中调用

您的 dbaccess 代码出现 panic 。检查您如何处理那里的所有错误:

2020-01-06T18:46:26.697592+00:00 app[web.1]: /app/tmp/cache/go1.12.12/go/src/runtime/panic.go:522 +0x1b5 2020-01-06T18:46:26.697595+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/dbconnect.runQuery(0xc0000946e0, 0x150, 0x0) 2020-01-06T18:46:26.697597+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/dbconnect/connectdb.go:78 +0xff 2020-01-06T18:46:26.697599+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/dbconnect.PointsGdTableQuery(0xc0000946e0, 0x150, 0x0, 0x0, 0x0) 2020-01-06T18:46:26.697601+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/dbconnect/connectdb.go:161 +0x64 2020-01-06T18:46:26.697604+00:00 app[web.1]: github.com/amunnelly/gowebappdatabase/routing.ServeHome(0x8db260, 0xc0001b2000, 0xc000128100) 2020-01-06T18:46:26.697606+00:00 app[web.1]: /tmp/build_b7c9c282f9c067c1b5b5cede1994472d/routing/routing.go:35 +0x1b5

关于postgresql - Heroku Go WebApp 错误 - 连接关闭而没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59617618/

相关文章:

api - URL 查询参数或媒体类型参数(在 Accept header 中)来配置对 HTTP 请求的响应?

php - 如何在不减慢响应速度的情况下调用微服务?

docker - 如何在 Golang 的时间戳中添加五分钟?

performance - 我怎样才能加快表之间的差异?

java - ClassCastException:org.postgresql.jdbc4.Jdbc4Connection 无法转换为 org.postgresql.jdbc4.Jdbc4Connection

ruby - ruby 中等效的 curl 命令

go - 处理大量查询并避免重复

sql - 如何计算 varchar 字段中的每个字符?

mysql - 在将此插入写入查询时需要一些帮助,什么是有效的方法?

rest - 通过REST API实现服务器端对长时间轮询的响应