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

Fix launching a browser results in closed file already closed error #648

Open
inancgumus opened this issue Nov 11, 2022 · 5 comments · Fixed by #735
Open

Fix launching a browser results in closed file already closed error #648

inancgumus opened this issue Nov 11, 2022 · 5 comments · Fixed by #735
Labels
bug Something isn't working ci

Comments

@inancgumus
Copy link
Member

inancgumus commented Nov 11, 2022

Brief summary

TestBrowserCrashErr ends with the following error when trying to launch a browser:

--- FAIL: TestBrowserCrashErr (0.03s)
    browser_test.go:151: 
        	Error Trace:	/home/runner/work/xk6-browser/xk6-browser/tests/page_test.go:705
        	            				/home/runner/work/xk6-browser/xk6-browser/tests/browser_test.go:151
        	Error:      	Error "GoError: launching browser: read |0: file already closed" does not contain "launching browser: Invalid devtools server port"
        	Test:       	TestBrowserCrashErr

Although we only observe the error on CI for now. It can be problematic in some instances when users launch a browser too. We need to fix it before it happens again.

xk6-browser version

79b7f08

OS

Github CI

Chrome version

107.0.5304.110

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Last detected in: TestBrowserCrashErr .

https://github.com/grafana/xk6-browser/actions/runs/3438417446/jobs/5734442790

Expected behaviour

No error.

Actual behaviour

Error.

Related issues

#415, #363.

@inancgumus inancgumus added the bug Something isn't working label Nov 11, 2022
@inancgumus inancgumus added this to the v0.7.0 milestone Nov 11, 2022
@inancgumus inancgumus self-assigned this Nov 11, 2022
@inancgumus inancgumus changed the title Fix while launching a browser results in closed file already closed error Fix launching a browser results in closed file already closed error Nov 11, 2022
@andrewslotin andrewslotin modified the milestones: v0.7.0, v0.8.0 Jan 3, 2023
@inancgumus inancgumus removed their assignment Jan 18, 2023
@ankur22 ankur22 self-assigned this Jan 23, 2023
@ankur22
Copy link
Collaborator

ankur22 commented Jan 24, 2023

I was able to reproduce this issue with the help of https://stackoverflow.com/questions/70422836/error-in-reading-the-byte-read-0-file-already-closed-in-go. I wasn't able to reproduce this just by stress testing the test unfortunately. It had to be done in a manual way:

  1. Checkout 79b7f08.
  2. Use the following diff:
      diff --git a/common/browser_process.go b/common/browser_process.go
      index 78de55d..8fc5a7c 100644
      --- a/common/browser_process.go
      +++ b/common/browser_process.go
      @@ -159,6 +159,10 @@ func execute(
       		return command{}, fmt.Errorf("%w", ctx.Err())
       	}
       
      +	if cmd.Process != nil && cmd.Process.Pid != 0 {
      +		fmt.Println(cmd.Process.Pid)
      +	}
      +
       	done := make(chan struct{})
       	go func() {
       		// TODO: How to handle these errors?
      diff --git a/tests/test_browser.go b/tests/test_browser.go
      index 26bfa7e..710eee7 100644
      --- a/tests/test_browser.go
      +++ b/tests/test_browser.go
      @@ -355,7 +355,7 @@ type withLaunchOptions = launchOptions
       // defaultLaunchOptions returns defaults for browser type launch options.
       // TestBrowser uses this for launching a browser type by default.
       func defaultLaunchOpts() launchOptions {
      -	headless := true
      +	headless := false
       	if v, found := os.LookupEnv("XK6_BROWSER_TEST_HEADLESS"); found {
       		headless, _ = strconv.ParseBool(v)
       	}
      
  3. Place a breakpoint at line 183 in browser_process.go (after applying the diff above).
  4. Debug run TestBrowserCrashErr.
  5. It should stop on line 183, and the PID of the newly launched browser should be in the debug console.
  6. Use kill -9 {PID_NUM} (and replace {PID_NUM} with the actual pid num.
  7. Now hit Continue.
  8. You should end up with the same error.

Obviously this isn't a great way to replicate the issue. What it does show is that it's somewhat out of our control if the browser process die. Happy to discuss solutions, maybe we retry the launch?

@ankur22
Copy link
Collaborator

ankur22 commented Jan 26, 2023

After a quick discussion, here are the next steps:

  1. Improve the error message.
  2. See if we can set a minimum VM machine on Github actions so that the browser instance doesn't crash due to resource limitations.

ankur22 added a commit that referenced this issue Jan 26, 2023
When the browser fails to load prior to xk6-browser connecting to it
via CDP, then we need to make it clear what's happened.

Partially Closes: #648
ankur22 added a commit that referenced this issue Jan 27, 2023
When the browser fails to load prior to xk6-browser connecting to it
via CDP, then we need to make it clear what's happened.

Partially Closes: #648
@ankur22
Copy link
Collaborator

ankur22 commented Jan 27, 2023

I believe the Github Action Runners provide enough computer power to run the tests: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources.

WDYT @inancgumus @ka3de?

@ankur22
Copy link
Collaborator

ankur22 commented Jan 27, 2023

@ka3de has been hitting this issue frequently today e.g. https://github.com/grafana/xk6-browser/actions/runs/4025838004/jobs/6919871984. I'll try to investigate within the CI job (lots of logging).

@ankur22 ankur22 reopened this Feb 2, 2023
@ankur22 ankur22 modified the milestones: v0.8.0, v0.9.0 Feb 2, 2023
@ankur22 ankur22 removed their assignment Feb 9, 2023
@inancgumus inancgumus assigned inancgumus and unassigned inancgumus Feb 24, 2023
@inancgumus
Copy link
Member Author

@grafana/k6-browser I've removed my assignment as I have yet to work on it.

@inancgumus inancgumus added the ci label Mar 31, 2023
@inancgumus inancgumus removed this from the v0.9.0 milestone Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ci
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants