Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用server.Stop()时无法正常终止程序。 #67

Closed
ycg000344 opened this issue Apr 3, 2020 · 3 comments
Closed

调用server.Stop()时无法正常终止程序。 #67

ycg000344 opened this issue Apr 3, 2020 · 3 comments

Comments

@ycg000344
Copy link

变动

server.Serve()中添加了如下代码:

//运行服务
func (s *Server) Serve() {
	s.Start()
	//TODO Server.Serve() 是否在启动服务的时候 还要处理其他的事情呢 可以在这里添加
	//阻塞,否则主Go退出, listenner的go将会退出
	exits := make(chan os.Signal, 1)
	signal.Notify(exits, os.Interrupt, os.Kill)
	select {
	case <-exits:
		s.Stop()
		return
	}
}

异常情景

clientserver socket正常通信,在终端中手动停止掉 go run server.go, client方日志显示正常的socket关闭,但是在server这里执行connection.Close()卡住。

终端的一些日志:

connection add to ConnManager successfully: conn num =  1
[Writer Goroutine is running]
[Reader Goroutine is running]
^C[STOP] Zinx server , name  ZinxServerApp
Conn Stop()...ConnID =  0
127.0.0.1:54887 [conn Writer exit!]
read msg head error  read tcp4 127.0.0.1:8999->127.0.0.1:54887: use of closed network connection
Conn Stop()...ConnID =  0
127.0.0.1:54887 [conn Reader exit!]
^C^C^C^C^C^C^C^C^Z
[1]  + 43852 suspended  go run server.go
@volgariver6
Copy link

我也遇到这个卡住不退出的情况,跟了一下代码,根本原因是死锁问题导致的。
在调用Server.Stop() 的时候,执行了:
s.ConnMgr.ClearConn() <------(1)
在ClearConn() 中,执行了conn.Stop()。
在conn.Stop()中又调用了ConMgr的Remove() <------(2)

在(1)和(2)中都要拿到锁connMgr.connLock.Lock(),所以在调用Remove()的时候就卡住了,这应该是一个bug。

@ycg000344
Copy link
Author

@lauber00 感谢,刚才检查了代码,确实是这种情况,删除了 ClearConn里面的锁来解决了。

@AleDaDa
Copy link

AleDaDa commented Aug 25, 2020

这问题似乎没有提交给维护团队, 那大家都直接魔改源码么

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants