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

当浏览器关闭时,chrome_crashpad_handler和Chromium Helper两个进程没有被关闭。 #1006

Open
DC3x6 opened this issue Jan 26, 2024 · 3 comments
Labels
question Questions related to rod upstream Upstream issue that can't solved by Rod

Comments

@DC3x6
Copy link
Contributor

DC3x6 commented Jan 26, 2024

Rod Version: v0.114.5

在多协程的情况下,每个协程开始时初始化一个浏览器,浏览器关闭时,chrome_crashpad_handler和Chromium Helper两个进程没有被关闭,导致内存占满。

func main() {
 var swg = sizedwaitgroup.New(10)
 for i := 0; i < 100; i++ {
 	swg.Add()
 	go func(num int) {
 		defer swg.Done()
 		println(num)
 		browser := testrod.NBrowser()
 		defer browser.MustClose()
 		page := browser.Timeout(20 * time.Second).MustPage()
 		navigation := page.MustWaitNavigation()
 		page.MustNavigate("https://www.google.com/")
 		navigation()
 		time.Sleep(5 * time.Second)
 	}(i)
 }
 swg.Wait()

}

headless

	launch := launcher.New().
		//Leakless(true).
		Set("disable-gpu", "true").
		Set("ignore-certificate-errors", "true").
		Set("ignore-certificate-errors", "1").
		Set("disable-crash-reporter", "true").
		Set("hide-scrollbars", "true").
		Set("mute-audio", "true").
		Set("incognito", "true").
		Headless(true).
Bin(brpath).
		MustLaunch()

browser := rod.New().NoDefaultDevice().ControlURL(launch).MustConnect().MustIgnoreCertErrors(true)
image image
@DC3x6 DC3x6 added the question Questions related to rod label Jan 26, 2024
Copy link

Please fix the format of your markdown:

3:91 MD026/no-trailing-punctuation Trailing punctuation in heading [Punctuation: '。']
29 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
29 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
44 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
45:1 MD033/no-inline-html Inline HTML [Element: img]
46:1 MD033/no-inline-html Inline HTML [Element: img]

generated by check-issue

@ysmood
Copy link
Collaborator

ysmood commented Jan 26, 2024

如果 leakless 都不行,那么 chrome 就非常像病毒了。你只能自己处理他的进程了,这是拿到 stdlib 的 cmd 对象的例子:

func Example_custom_launch() {
// get the browser executable path
path := launcher.NewBrowser().MustGet()
// use the FormatArgs to construct args, this line is optional, you can construct the args manually
args := launcher.New().FormatArgs()
var cmd *exec.Cmd
if true { // decide whether to use leakless or not
cmd = leakless.New().Command(path, args...)
} else {
cmd = exec.Command(path, args...)
}
parser := launcher.NewURLParser()
cmd.Stderr = parser
utils.E(cmd.Start())
u := launcher.MustResolveURL(<-parser.URL)
rod.New().ControlURL(u).MustConnect()
}

你使用 exec 库的话就和 rod 无关了,这部分实在难以调试和复现。

@ysmood ysmood added the upstream Upstream issue that can't solved by Rod label Jan 26, 2024
@hktalent
Copy link

@ysmood

util "github.com/GhostTroops/go-utils"

var fE = func() error {
		browser.MustClose()
		chromeLauncher.Cleanup()
		chromeLauncher.Kill()
		return nil
	}
	defer func() {
		if err := recover(); nil != err {
			log.Println(err)
			fE()
		}
	}()
	util.NewExit().RegClose(fE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod upstream Upstream issue that can't solved by Rod
Projects
None yet
Development

No branches or pull requests

3 participants