Golang HTTP server timeout

心已入冬 提交于 2019-12-13 02:25:20

问题


I'm trying to write a web server in golang to handle geocoding requests. Some of these requests take longer than a minute to process. In this case, the server seems to be returning an empty body to the client, though the handler keeps running. I've tried the code below to no avail. Am I missing something? Is it possible this is a problem with pat?

r := pat.New()

r.Get("/geocode", GeocodeHandler)
r.Get("/status", StatusHandler)
r.Get("/", InvalidHandler)

s := &http.Server{
    Addr: ":"+port,
    Handler: r,
    ReadTimeout: 10 * time.Minute,
    WriteTimeout: 10 * time.Minute,
    MaxHeaderBytes: 0,
}

s.ListenAndServe()

The client is in ruby. I don't believe that's the problem though, since I see similar behavior if I use curl.

uri = URI(URI.escape("http://blah.com/geocode?address=#{address}"))
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 10 * 60
response = http.request(Net::HTTP::Get.new(uri.request_uri))

回答1:


Found the issue. I didn't mention that my server was behind an Amazon ELB. Its default timeout is 60 seconds.



来源:https://stackoverflow.com/questions/17690380/golang-http-server-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!