Giter VIP home page Giter VIP logo

Comments (6)

concn avatar concn commented on June 5, 2024

go版本1.18
windows server2008R2
gnet v1.6.5版本

from gnet.

panjf2000 avatar panjf2000 commented on June 5, 2024

两种关闭 gnet server 的方法都可以使用,没有本质区别,重新启动的逻辑需要你自己控制。

from gnet.

concn avatar concn commented on June 5, 2024

目前升级到gnet V2.3.3版本
go版本1.18
windows server2008R2

image

func (es *echoServer) OnShutdown(srv gnet.Engine) {
ZapLogger.Info("Echo server is shutdown")
go RunGNetServer(5016, true, false)
}

在OnTraffice里返回gnet.Shutdown会触发关闭 OnShutdown方法, 在OnShutdown方法里再调用RunGNetServer(5016, true, false)后,启动不了,显示错误:
panic: listen tcp :5016: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

是之前的启动RunGNetServer的Server没有关闭吗? 需要怎么关闭上次的这个5016端口的gnet监听的server呢?

from gnet.

panjf2000 avatar panjf2000 commented on June 5, 2024

OnShutdown 的时候整个流程还没走完,还有你为什么非要在代码里控制重启的流程,一般不建议这么搞(不限于 gnet server),直接退出进程然后重启不就行了。

from gnet.

concn avatar concn commented on June 5, 2024

image
因为我们程序没有主动闭连接,客户端也没有主动关闭socket;但是可能是网络不稳定或什么原因,导致了连接客户端又直接发起了新的连接,老的连接关闭触发了OnClose,这样一般跑一二个小时,客户端有1600个;有时候跑一二天,就会出现出问题。如上图,这时候没有新连接上来,因为telnet ip 5016端口是不通的;端口已经不通了;在服务器主机telnet 127.0.0.1 5016也是不通的。也没什么错误输出,程序停在那里,。重启程序后,又马上可以用了,这样不断的重启这个问题。所以就需要判断是出现这个情况的时候,就需要关掉之前的gnet.Run,重新gnet.Run一下这个端口监听;。
有三个问题请教:
1.用在React() 方法返回 return nil, gnet.Shutdown ,如何判断之前的gnet.Run的server(监听5016)彻底关掉了,好重新gnet.Run一下5016
2.如果用第二种方法gnet.Stop(ctx context.Context, protoAddr string) ,就是var ctx context.Context 然后和gnet.Run中参数protoAddr传进来调用gnet.Stop就可以了是吗? 另外我看Stop不推荐使用了。
3.gnet.Run(gnet.WithTCPKeepAlive(12*time.Minute)) 这个KeepAlive参数,是tcp本身的机制时间呢,还是客户端发数据心跳即OnTraffic里收到数据的时间呢? 我们是5分钟一个客户端数据心跳。
问的问题有点多,因为对这些稍微有些深度的东西不太懂,感谢回答!

from gnet.

panjf2000 avatar panjf2000 commented on June 5, 2024

这种端口不通的问题我建议你在服务端排查一下,看看你的网络进程还有没有在正常监听端口,或者分析一下是不是进程因为某种原因卡死了,可以用 go-delve 进入进程调试一下。

另外,gnet 的 Windows 版本只是为了方便开发调试,所以这个版本没有做很细致的优化,性能方面没有保证,而且不像 gnet 的 Linux/macOS 版本已经在很多公司的生产环境部署使用很长时间,Windows 版本并没有很多生产环境的验证,因此稳定性也不能保证,通常不建议用在生产环境;鉴于你也不是很了解底层,我建议你不要用 gnet 这种底层的网络框架,直接用 Go 的 net 标准网络库,代码会更好写一点,而且你写业务代码出 bug 的概率也更低一点。

from gnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.