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 #1148

Closed
2 tasks done
Tracked by #1138
rauldeheer opened this issue Jan 4, 2024 · 7 comments
Closed
2 tasks done
Tracked by #1138
Assignees
Labels
bug Something isn't working

Comments

@rauldeheer
Copy link

rauldeheer commented Jan 4, 2024

Brief summary

We're trying to run a test within our application using the k6x-browser. We're encountering a weird issue where the test sometimes crashes with the following error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x98 pc=0x1def4c9]
register [--------------------------------------] 1 VUs 00m30.9s/16m40s 0/1 iters, 1 per VU
goroutine 12019 [running]:
github.com/grafana/xk6-browser/common.(*Frame).ID(0x213f5e0?)
github.com/grafana/xk6-browser@v1.2.1/common/frame.go:1327 +0x29
github.com/grafana/xk6-browser/common.(*FrameSession).initIsolatedWorld(0xc0002daa50, {0x23b0e8a, 0x1c})
github.com/grafana/xk6-browser@v1.2.1/common/frame_session.go:421 +0x45a
github.com/grafana/xk6-browser/common.NewFrameSession({0x2688968, 0xc0004ac0a0}, {0x268f738?, 0xc0013be320?}, 0xc000683ba0, 0xc000e1e6e0, {0xc0003927a0, 0x20}, 0xc00037f830)
github.com/grafana/xk6-browser@v1.2.1/common/frame_session.go:134 +0x938
github.com/grafana/xk6-browser/common.(*FrameSession).attachIFrameToTarget(0xc000e1e6e0, 0xc002b6ba70, {0xc000392780, 0x20})
github.com/grafana/xk6-browser@v1.2.1/common/frame_session.go:905 +0xe5
github.com/grafana/xk6-browser/common.(*FrameSession).onAttachedToTarget(0xc000e1e6e0, 0xc002663520)
github.com/grafana/xk6-browser@v1.2.1/common/frame_session.go:838 +0x271
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents.func1()
github.com/grafana/xk6-browser@v1.2.1/common/frame_session.go:267 +0x3f0
created by github.com/grafana/xk6-browser/common.(*FrameSession).initEvents in goroutine 77
github.com/grafana/xk6-browser@v1.2.1/common/frame_session.go:216 +0x19b

k6 version

0.48.0

OS

macOS 14 (arm) - Sonoma 14.2.1 (23C71)

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Use a browser test and navigate through multiple pages. Try it a few times, eventually it will crash.

Expected behaviour

No crash, or at least a more detailed error.

Actual behaviour

Crashing with a GoLang error

Tasks

@rauldeheer rauldeheer added the bug Something isn't working label Jan 4, 2024
@olegbespalov olegbespalov transferred this issue from grafana/k6 Jan 4, 2024
@olegbespalov olegbespalov removed their assignment Jan 4, 2024
@olegbespalov
Copy link
Contributor

Hey @rauldeheer !

Thanks for reporting this. I've moved it to an appropriate repository.

Also, can you share a minimal example of the script (without sharing your internals) that is causing that panic?

Thanks!

@rauldeheer
Copy link
Author

@olegbespalov Hey!

Thanks for responding, but unfortunately it will be hard for me to provide you with an example, as we have a big case with a specific private application. However, we're only navigating through pages and it sometimes just crashes. It never crashes on the same line, it's random.

What could I do to make this easier to test on your end?

What we do:

  1. Open 2 tabs.
  2. Do things in those tabs at the same time.
  3. Try until it crashes with the above error.

@olegbespalov
Copy link
Contributor

@rauldeheer to me, it seems enough details for an attempt to reproduce the bug, but the k6-browser team will get back to you once they have a chance to have a look and prioritize this issue 👍

Thanks!

@rauldeheer
Copy link
Author

rauldeheer commented Jan 9, 2024

@olegbespalov Thank you and I'm looking forward to seeing the result of this issue.

@rauldeheer
Copy link
Author

For extra reference, here's the script. Since it has almost no context to the application we can easily share it with the world:

import { type Options } from 'k6/options';
import { type Page, browser } from 'k6/experimental/browser';
import { sleep } from 'k6';
import { BASE_URL } from '../config/constants';

export const options: Options = {
	scenarios: {
		register: {
			executor: 'per-vu-iterations',
			vus: 1,
			maxDuration: '1000s',
			options: {
				browser: {
					type: 'chromium'
				}
			}
		}
	}
};

export default async function () {
	const context = browser.newContext();
	context.grantPermissions(['camera', 'microphone', 'clipboard-write']);

	const mainPage = context.newPage();
	const controlsPage = context.newPage();

	await signIn(mainPage);
	await turnOnStream(mainPage);
	// // console.log(mainPage.url());
	// sleep(1);
	await gameLoop(controlsPage, mainPage.url());
	// sleep(Infinity);
}

async function signIn(page: Page) {
	await page.goto(BASE_URL + '/login/password?from=%2Fwelcome');
	sleep(5);

	const usernameInput = page.locator('input[data-cy="username"]');
	usernameInput.type('admin');

	const passwordInput = page.locator('input[data-cy="password"]');
	passwordInput.type('Test123!');

	const loginButton = page.locator('button[type="submit"]');
	await loginButton.click();

	sleep(1);
}

async function turnOnStream(page: Page) {
	await page.goto(BASE_URL + '/admin/game', { waitUntil: 'networkidle' });
	sleep(5);
	const viewButton = page.locator('[data-test="game-page-btn-0"');
	await viewButton.click();
	sleep(4);

	const streamButton = page.locator('[data-test="admin-tab-stream-chat"');
	await streamButton.click();

	sleep(5);

	const publishButton = page.locator('[data-test="publish-button"]');
	await publishButton.click();

	// sleep(3);
	// await publishButton.click();

	sleep(2);

	console.log('sdf');
}

async function gameLoop(page: Page, gameUrl: string) {
	// await page.goto('https://www.google.com/');
	// sleep(Infinity);
	// console.log('89045860945809');
	// sleep(3);
	// page.waitForLoadState('networkidle');
	await page.goto(gameUrl, { waitUntil: 'networkidle' });

	sleep(100);

	// sleep(10);
	// console.log('sdf');

	// page.waitForSelector('[data-test="admin-tab-live-controls"]');

	// const controlsButton = page.locator('[data-test="admin-tab-live-controls"]');
	// await controlsButton.click({ button: 'middle' });

	// sleep(1);

	// page.waitForSelector('[data-test="game-start-button"] :not(disabled)', {
	// 	timeout: 0
	// });

	// console.log('button freed.');
	// sleep(10);
	// const startButton = page.locator('[data-test="game-start-button"]');

	// await startButton.click();

	// sleep(Infinity);
}

@ankur22
Copy link
Collaborator

ankur22 commented Jan 9, 2024

Hi @rauldeheer,

Thanks for the details and test test script. Is there any chance you've been able to recreate this against a publicly accessible website? I've not been able to reproduce the issue yet, but i'm guessing the website under test is one that contains iframes?

From an issue standpoint it would seem that the issue lies here where the frame is nil when trying to retrieve the id of it. There's a comment in the link which references a scenario where the "frame could be removed before we execute this"

@ankur22
Copy link
Collaborator

ankur22 commented Jan 11, 2024

@rauldeheer we think we've fixed the issue, and the fix will be in the next release of k6 (v0.49.0). If you would like to test the latest version of the browser module with the fix (and if you have Go installed) then follow these instructions:

  1. run go install go.k6.io/xk6/cmd/xk6@latest to download the xk6 tool which will help build k6 with the latest version of the browser module.
  2. run xk6 build --with github.com/grafana/xk6-browser@main to build k6 with the latest version of the browser module.
  3. Now run your test script with the newly built k6 binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants