dongzhang4301 2016-04-22 20:23
浏览 187

Golang卡住,直到我按CTRL + C(Windows 10)

I've got a server-like program in Windows 10 where the main program waits for the requests with http.Handle(dst, handlerStruct), and for every query does the corresponding operations and returns a result or just prints something through the screen.

It usually works fine, but sometimes, and just sometimes, when I leave the program running "waiting" for requests to come in for a long time (3 minutes up) and then I send a request, it just gets "stucked" until I press CTRL+C, and then it returns the values inmediately. So it looks like the program runs well, but the returning thread is having a break or something when I leave it a long time without requests.

This happens ever since I started developing the program, and not only when using functions with goroutines.

For me it looks like it has more to do with Windows 10 than with Golang itself, but it's just very annoying, and of course I don't want this to happen with my server...

Hope you can see what's going wrong here...

Thanks.


EDIT

This is the main program waiting for the requests:

func main() {

    runtime.GOMAXPROCS(10000000)

    http.Handle("/sameDayCombinations", CBR.SameDayCombinationsHandler{})
    http.ListenAndServe(":8080", nil)
}

Now this is the code of ServeHTTP for the handler:

func (h SameDayCombinationsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

    t1 := time.Now()

    q := common.DecodeRequest(r)
    json := common.EncodeAnswer((&h).RetrieveSpecificSolutions(q.Year, q.Month, q.Day, q.DepID, q.ArrID, q.Adults, q.Children, q.Infants), true)
    fmt.Fprintf(w, json)

    t2 := time.Now()
    fmt.Println(t2.Sub(t1))
}

EDIT2

Here I add the stack of a program execution after the appearance of this weird behavior. So, after doing CTRL+C I got this; looks pretty normal to me.

http://pastebin.com/DduvtNZr

Though, now, by empirical demonstration, I'm sure it has to do with the console Prints (probably large prints?). That's a good new, cause it'll only happen while debugging, but stills a weird behavior...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探