问题描述

我正在尝试用golang写一个Web服务器来处理地理编码请求.其中一些请求需要花费一分钟以上的时间来处理.在这种情况下,尽管处理程序一直在运行,但是服务器似乎正在向客户端返回一个空的主体.我尝试了下面的代码无济于事.我想念什么吗? pat 可能有问题吗?

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()

客户在使用红宝石.但我不认为这是问题所在,因为如果使用curl,我会看到类似的行为.

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))

推荐答案

发现了问题.我没有提到我的服务器在Amazon ELB后面.其默认超时为60秒.

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

这篇关于Golang HTTP服务器超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!