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

长时间运行报错:panic: runtime error: invalid memory address or nil pointer dereference #4

Closed
MisakaFxxk opened this issue Jul 31, 2023 · 4 comments

Comments

@MisakaFxxk
Copy link

问题描述

运行一段时间过后程序会报错自动退出,使用了socket5代理,systemctl内的日志是:
7月 30 17:50:25 ECS774 sniproxy[1233074]: panic: runtime error: invalid memory address or nil pointer dereference
7月 30 17:50:25 ECS774 sniproxy[1233074]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x557721]
7月 30 17:50:25 ECS774 sniproxy[1233074]: goroutine 6 [running]:
7月 30 17:50:25 ECS774 sniproxy[1233074]: main.startSniProxy.func1({0x5c8ac0?, 0xc00000c1e0})
7月 30 17:50:25 ECS774 sniproxy[1233074]: C:/Github/SNIProxy/main.go:110 +0x101
7月 30 17:50:25 ECS774 sniproxy[1233074]: created by main.startSniProxy
7月 30 17:50:25 ECS774 sniproxy[1233074]: C:/Github/SNIProxy/main.go:103 +0x1a5
7月 30 17:50:25 ECS774 systemd[1]: sniproxy.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
7月 30 17:50:25 ECS774 systemd[1]: sniproxy.service: Failed with result 'exit-code'.
7月 30 17:50:25 ECS774 systemd[1]: sniproxy.service: Consumed 18.125s CPU time.

软件版本

v1.0.0

附加截图

No response

@XIU2
Copy link
Owner

XIU2 commented Jul 31, 2023

难以复现,不好解决,我这边从写完开始就自用了,两个多月也没遇到过。。。

@lifei6671
Copy link

	go func(listener net.Listener) {
		defer listener.Close()
		for {
			connection, err := listener.Accept()
			if err != nil {
				serviceLogger(fmt.Sprintf("接受连接请求时出错: %v", err), 31, false)
			}
			raddr := connection.RemoteAddr().(*net.TCPAddr)
			serviceLogger("连接来自: "+raddr.String(), 32, false)
			go serve(connection, raddr.String()) // 有新连接进来,启动一个新线程处理
		}
	}(listener)

这段代码,如果listener.Accept()返回的err的时候就会panic。

@sheeye
Copy link

sheeye commented Sep 21, 2023

go func(listener net.Listener) {
	defer listener.Close()
	for {
		connection, err := listener.Accept()
		if err != nil {
			serviceLogger(fmt.Sprintf("接受连接请求时出错: %v", err), 31, false)
			continue
		}
		raddr := connection.RemoteAddr().(*net.TCPAddr)
		serviceLogger("连接来自: "+raddr.String(), 32, false)
		go serve(connection, raddr.String()) // 有新连接进来,启动一个新线程处理
	}
}(listener)

加个continue就可以了吧。

ShadowSharksR added a commit to ShadowSharksR/SNIProxy that referenced this issue Oct 2, 2023
@XIU2
Copy link
Owner

XIU2 commented Apr 1, 2024

感谢楼上两位,顺手给修了哈~(v1.0.1 版本


另外,系统服务配置文件里我忘记加上用于守护进程的配置项了(Restart=on-failure),因此在 SNIProxy 服务异常退出后,没有自动恢复启动,修改下服务配置文件加上这个试试。这样对于一些小概率报错引起的异常退出,也不用担心来不及恢复了。
# Linux 配置为系统服务 (systemd - 以支持开机启动、守护进程等)

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

4 participants