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

使用restart #65

Open
gy0624ww opened this issue Feb 18, 2024 · 6 comments
Open

使用restart #65

gy0624ww opened this issue Feb 18, 2024 · 6 comments

Comments

@gy0624ww
Copy link

gy0624ww commented Feb 18, 2024

发信号
kill -SIGHUP 12068
之后报这个错误
jsonrpc2.go:201: ERROR: error in JSONRPC server: *errors.errorString http: Server closed
虽然可以成功起动一个新进程来监听端口,但是这个错误是正常的吗?

type Server struct {
	engine    *server.Server
	apiRouter *Router
}

func (s *Server) Start() {
	s.apiRouter.With(s.engine)
	s.engine.Serve("tcp", "localhost:8972")
	//s.engine.Serve("reuseport", "localhost:8972")
}


func (s *Server) StartShutdownListener() {
	go func(s *Server) {

		log.Println("server pid:", os.Getpid())

		// channel to receive notifications of SIGTERM and SIGHUP
		ch := make(chan os.Signal, 1)
		signal.Notify(ch, syscall.SIGTERM, syscall.SIGHUP)

		// handle signal SIGTERM and SIGHUP
		switch <-ch {
		case syscall.SIGTERM:
			s.engine.RegisterOnShutdown(func(s *server.Server) {
				log.Println("graceful shutdown...")
			})
			s.engine.Shutdown(context.Background())
		case syscall.SIGHUP:
			s.engine.Restart(context.Background())
			s.engine.RegisterOnRestart(func(s *server.Server) {
				log.Println("graceful restart...")
			})
			s.engine.Restart(context.Background())
		}
	}(s)
}

go版本:
go version go1.20.1 linux/amd64
rpcx : v1.8.24

@smallnest 辛苦看一下 感谢

@smallnest
Copy link
Member

不用担心,这个是正常的.后续我会把这个log级别改成info

@gy0624ww
Copy link
Author

gy0624ww commented Feb 18, 2024 via email

@gy0624ww
Copy link
Author

@smallnest
还有一个问题请教下,就是调用restart()进行重启的时候,在重启过程中还是会有拒绝对外请求:

2024/02/21 14:48:26 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 14:48:26 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 14:48:26 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 14:48:26 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 14:48:26 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 14:48:26 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 14:48:26 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 14:48:26 failed to call: %v dial tcp 127.0.0.1:8972: connect: connection refused
2024/02/21 14:48:26 false
2024/02/21 14:48:27 failed to call: %v dial tcp 127.0.0.1:8972: connect: connection refused
2024/02/21 14:48:27: false
2024/02/21 14:48:27 failed to call: %v dial tcp 127.0.0.1:8972: connect: connection refused
2024/02/21 14:48:27: false
2024/02/21 14:48:27 failed to call: %v dial tcp 127.0.0.1:8972: connect: connection refused
2024/02/21 14:48:27 false
2024/02/21 14:48:28 failed to call: %v dial tcp 127.0.0.1:8972: connect: connection refused
2024/02/21 14:48:28 false
2024/02/21 14:48:28 true
2024/02/21 14:48:28 true
2024/02/21 14:48:28 true

不应该是重启的时候,单独起一个进程进行监听同一个端口,然后关闭其中一个(处理完活动连接),这种是正确的做法吗?
或者说,如何优雅的处理重启呢?能平滑的过度。有没有现成的例子呢?
感谢

@smallnest
Copy link
Member

使用graceful restart, 要求你的操作系统支持reuseport. windows不支持,现在的linux都支持了

https://github.com/rpcxio/rpcx-examples/tree/master/graceful_restart

@gy0624ww
Copy link
Author

@smallnest 嗯 我也尝试用过 有两个问题
1.每次重启都会产生新的进程,会导致越来越多的进程监听同一个端口,产生的进程ID是随机的,如何处理旧的进程呢?
2. 重启的一瞬间会产生这样的日志:

...
024/02/21 15:42:17 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 15:42:17 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF
2024/02/21 15:42:17 true

这种错误是正常的吗?谢谢

@gy0624ww
Copy link
Author

如果我用supervisor来守护进程的话,好像会有冲突,supervisor的拉起一个进程,程序的reuseport 拉起一个进程
这种怎么处理呢?

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

2 participants