Comments (6)
go版本1.18
windows server2008R2
gnet v1.6.5版本
from gnet.
两种关闭 gnet
server 的方法都可以使用,没有本质区别,重新启动的逻辑需要你自己控制。
from gnet.
目前升级到gnet V2.3.3版本
go版本1.18
windows server2008R2
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.
OnShutdown
的时候整个流程还没走完,还有你为什么非要在代码里控制重启的流程,一般不建议这么搞(不限于 gnet server),直接退出进程然后重启不就行了。
from gnet.
因为我们程序没有主动闭连接,客户端也没有主动关闭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.
这种端口不通的问题我建议你在服务端排查一下,看看你的网络进程还有没有在正常监听端口,或者分析一下是不是进程因为某种原因卡死了,可以用 go-delve 进入进程调试一下。
另外,gnet
的 Windows 版本只是为了方便开发调试,所以这个版本没有做很细致的优化,性能方面没有保证,而且不像 gnet
的 Linux/macOS 版本已经在很多公司的生产环境部署使用很长时间,Windows 版本并没有很多生产环境的验证,因此稳定性也不能保证,通常不建议用在生产环境;鉴于你也不是很了解底层,我建议你不要用 gnet
这种底层的网络框架,直接用 Go 的 net 标准网络库,代码会更好写一点,而且你写业务代码出 bug 的概率也更低一点。
from gnet.
Related Issues (20)
- [Question]: Will the OnTraffic function be called concurrently? HOT 1
- [Question]: Validate the approach of implementing persistent TCP connections. HOT 1
- [Bug]: Calling Dial() in version 2.4 of Windows 10 will block HOT 4
- [Question]: I would like to verify whether this problem in the screenshot will cause the memory of the service to slowly increase. HOT 1
- [Feature]: support edge-triggered I/O
- [Question]: Is the netpoll v1 version defaulting to horizontal triggering, and the V2 version defaulting to edge triggering? HOT 15
- [Bug]: fatal error: concurrent map read and map write HOT 1
- Inconsistent behaviors with SO_REUSEPORT on Linux and *BSD HOT 7
- Don't use SO_REUSEPORT on Unix domain sockets HOT 1
- Don't disable SO_REUSEPORT on DragonFlyBSD HOT 1
- [Question]: gnet client works not as expected even tho i did it according to the api ref HOT 1
- [Bug]: GNET client not working as expected HOT 4
- [Bug]: example gnet for echo tcp uses too much memory HOT 7
- [Bug]: Read returns io.ErrShortBuffer on closed connection HOT 7
- Special treatment for the first package HOT 8
- [Question]: How to shut down the started tcp server and turn off port listening? HOT 2
- [Question]: When using io.CopyBuffer(), do you need to call Flush to send the data? HOT 2
- [Bug]: Discard() panic HOT 17
- [Feature]: `io_uring` support HOT 1
- [Question]: there's gnet https server now, how to use gnet https client? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gnet.