HTTP连接卡在CLOSE_WAIT状态

huangapple go评论70阅读模式
英文:

http connections stuck in close_wait state

问题

我正在使用gin构建一个简单的API服务器。目前,在服务器启动几分钟后,所有传入的请求都被阻塞了。在检查连接状态后,我得到了如下的消息:HTTP连接卡在CLOSE_WAIT状态

我已经尝试设置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 :HTTP连接卡在CLOSE_WAIT状态

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.

huangapple
  • 本文由 发表于 2016年4月21日 10:58:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/36758798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定