英文:
http connections stuck in close_wait state
问题
我正在使用gin构建一个简单的API服务器。目前,在服务器启动几分钟后,所有传入的请求都被阻塞了。在检查连接状态后,我得到了如下的消息:
我已经尝试设置c.Request.Close=true或c.Header("Connection","close")或两者都设置,但都没有起作用。我想知道是否有人可以帮我解决这个问题。
更新-1 服务器启动方式如下:
runtime.GOMAXPROCS(runtime.NumCPU())
//开始服务
r := gin.New()
r.Use(gin.LoggerWithWriter(logFile))
r.Use(gin.RecoveryWithWriter(logFile))
r.Use(handler.SetResponseHeader())
controller.Router.RegisterRouter(r, cfg)
//r.Run(cfg.SvcHost)
s := &http.Server{
Addr: cfg.SvcHost,
Handler: r,
}
s.ListenAndServe()
更新-2
在临时禁用全局gorm.DB实例并为每个请求创建一个新的数据库连接后,这个问题不再出现。
英文:
I'm using gin to build a simple api server. right now, after the server started a few minutes later, all of incoming requests were stuck. After checking connections state , I got a message like below :
I already have tried to set c.Request.Close=true or c.Header("Connection","close") or both of them, but it was not working. I was wondering if anyone can help me fix this issue.
UPDATE-1 the way to start server
runtime.GOMAXPROCS(runtime.NumCPU())
//start serving
r := gin.New()
r.Use(gin.LoggerWithWriter(logFile))
r.Use(gin.RecoveryWithWriter(logFile))
r.Use(handler.SetResponseHeader())
controller.Router.RegisterRouter(r, cfg)
//r.Run(cfg.SvcHost)
s := &http.Server{
Addr: cfg.SvcHost,
Handler: r,
}
s.ListenAndServe()
UPDATE-2
after temporarily disabling the global gorm.DB instance and creating a new db connection for each request, this issue didn't occur any more.
答案1
得分: 1
TCP正在等待你关闭这些连接。可能你已经从它们那里读取了流的末尾,并忽略了它。
英文:
TCP is waiting for you to close those connections. Probably you have read end of stream from them and have ignored it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论