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

write tcp 127.0.0.1:46438->127.0.0.1:36667: use of closed network connection #915

Open
endachao opened this issue Aug 9, 2023 · 7 comments
Labels
question Questions related to rod

Comments

@endachao
Copy link

endachao commented Aug 9, 2023

Rod Version: v0.113.3

最近发现日志里面有一些 panic

write tcp 127.0.0.1:46438->127.0.0.1:36667: use of closed network connection

我这边是与 gin 搭配使用,首次运行时会初始化浏览器

func InitBrowser() {
	u := launcher.New().
		Set("no-sandbox").
		Set("disable-setuid-sandbox").
		Set("disable-gpu").
		Set("disable-dev-shm-usage").
		Set("unlimited-storage").
		Set("disable-accelerated-2d-canvas").
		Set("full-memory-crash-report").
		MustLaunch()
	RodBrowser = rod.New().ControlURL(u).MustConnect()
}

然后封装了一个接口,来生成 PDF,关键代码如下

p := RodBrowser.MustPage(url).MustWaitLoad()
defer p.MustClose()

wait := p.MustWaitRequestIdle()
wait()

// 等待元素可见
elem := p.MustElement(visibleDom)
elem.MustWaitVisible()

log.Println(url, "页面已经渲染好了,开始生成 PDF ")

pdf, err := p.PDF(&proto.PagePrintToPDF{
PaperWidth:      gson.Num(paperWidth),
PaperHeight:     gson.Num(paperHeight),
PrintBackground: true,
MarginTop:       gson.Num(marginTop),
MarginBottom:    gson.Num(marginBottom),
MarginLeft:      gson.Num(marginLeft),
MarginRight:     gson.Num(marginRight),
})

目前总是运行一段时间后,出现那个 panic 错误,重启后就可以恢复,没什么排查思路,请大佬帮忙看看

@endachao endachao added the question Questions related to rod label Aug 9, 2023
@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Please fix the format of your markdown:

3:18 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
4 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
4 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
10 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
27 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
27 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]

generated by check-issue

@ysmood
Copy link
Collaborator

ysmood commented Aug 9, 2023

抱歉,如果难以稳定复现的话我也不知道怎么帮忙

@endachao
Copy link
Author

我在考虑,是否是因为我全局初始化了,然后运行了一段时间后浏览器崩溃了

@Fly-Playgroud
Copy link
Contributor

Fly-Playgroud commented Aug 12, 2023

我在考虑,是否是因为我全局初始化了,然后运行了一段时间后浏览器崩溃了

如果是在Linux系统下运行的,考虑是否是共享内存用尽了,因为 Chrome 在Linux下会使用共享内存, dev-shm 使用命令行 flag ’–disable-dev-shm-usage 可以进行禁用

@ysmood
Copy link
Collaborator

ysmood commented Aug 12, 2023

@Fly-Playgroud 默认是禁用了呀

"disable-dev-shm-usage": nil,

@endachao 你试试最新版的 rod,说不定就没有问题了

@Fly-Playgroud
Copy link
Contributor

@Fly-Playgroud 默认是禁用了呀

"disable-dev-shm-usage": nil,

@endachao 你试试最新版的 rod,说不定就没有问题了

这可能是最近的版本加的吧,至少在0.113 版本上没有

@endachao
Copy link
Author

@ysmood @Fly-Playgroud

感谢两位回复,我确认我在启动前,已经设置了 disable-dev-shm-usage 这个参数了

func InitBrowser() {
	u := launcher.New().
		Set("no-sandbox").
		Set("disable-setuid-sandbox").
		Set("disable-gpu").
		Set("disable-dev-shm-usage").   // 在这里已经设置为 disable 了
		Set("unlimited-storage").
		Set("disable-accelerated-2d-canvas").
		Set("full-memory-crash-report").
		MustLaunch()
	RodBrowser = rod.New().ControlURL(u).MustConnect()
}


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

No branches or pull requests

3 participants