Invalid Memory Address

I am getting this Error when running K6 Browser locally any help?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=

These is my options:

export const options = {
  scenarios: {
    browser: {
      executor: 'constant-vus',
      vus: 10,
      duration: '5m',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    }
}
};

Hi @chingher90, welcome to the community forum!

Can you share the sanitized version of the test script also with us?

1 Like

@bandorko

Here is the sanitized version

import { browser } from 'k6/experimental/browser';
import { sleep, check } from 'k6';
import { SharedArray } from "k6/data";
import papaparse from "https://jslib.k6.io/papaparse/5.1.1/index.js";

export const options = {
  scenarios: {
    browser: {
      executor: 'constant-vus',
      vus: 10,
      duration: '5m',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    }
}
};

  // not using SharedArray here will mean that the code in the function call (that is what loads and
  // parses the csv) will be executed per each VU which also means that there will be a complete copy
  // per each VU
const csvData = new SharedArray("UserData", function () {
  // Load CSV file and parse it using Papa Parse
  return papaparse.parse(open("./data/randomData.csv"), { header: true }).data;
});

  // Pick a random userID test data pair
  const getCSVRandomData = csvData[Math.floor(Math.random() * csvData.length)];
  console.log("Selected UserName Data: ", JSON.stringify(getCSVRandomData));

export default async function () {
  const page = browser.newPage();

  try {
    await page.goto('https://FAKE_URL.com/index.html');
    page.locator('input[name="username"]').type(getCSVRandomData.users);
    page.locator('input[name="password"]').type(getCSVRandomData.password);
    const submitButton = page.locator("LOGINBUTTON_XPATH");
    await Promise.all([page.waitForNavigation(), submitButton.click()]);
    sleep(1.0)
    //Navigate to another page after login
    page.goto ('https://FAKE_URL.com');
    sleep(1.0)
    const text = page.locator('XPATH');
    if (text.isVisible()) {
      console.log("element is visible");
    }
    
  } finally {
    const signoutButton = page.locator('SIGNOUT_XPATH');
    if (signoutButton.isVisible()) {
      await Promise.all([page.waitForNavigation(), signoutButton.click()]);
      console.log(" Test Successfully Sign out");
    }else{
      console.log("SignOut failed to locate");
    };
    page.close();
  }
}


I confirm the script will work if I just config for only one VU for one iteration but if I bump up the VUs like the above settings …it will crash.

@chingher90: Are there any stacktrace in the error message?

I have the same error, also hapenning only when I use maultiple VUs. Here is my scenario:

{
        executor: 'constant-vus',
        vus: 10,
        duration: `4.5m`,
        gracefulStop: '30s',
        options: {
            browser: {
                type: 'chromium',
            },
        }
    }

Here is the error stack:

ERRO[0160] panic: runtime error: invalid memory address or nil pointer dereference
goroutine 182 [running]:
runtime/debug.Stack()
csTimeSeruntime/debug/stack.go:24 +0x64
go.k6.io/k6/js/common.RunWithPanicCatching.func1()
csExplaigo.k6.io/k6/js/common/util.go:82 +0x190
panic({0x101dc1960?, 0x102dc8c70?})
        runtime/panic.go:914 +0x218
github.com/dop251/goja.(*Runtime).runWrapped.func1()
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/runtime.go:2442 +0x168
panic({0x101dc1960?, 0x102dc8c70?})
        runtime/panic.go:914 +0x218
github.com/dop251/goja.(*vm).handleThrow(0x14002437320, {0x101dc1960, 0x102dc8c70})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:788 +0x3e0
github.com/dop251/goja.(*vm).try.func1()
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:807 +0x48
panic({0x101dc1960?, 0x102dc8c70?})
        runtime/panic.go:914 +0x218
github.com/dop251/goja.(*vm).handleThrow(0x14002437320, {0x101dc1960, 0x102dc8c70})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:788 +0x3e0
github.com/dop251/goja.(*vm).runTryInner.func1()
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:830 +0x48
panic({0x101dc1960?, 0x102dc8c70?})
        runtime/panic.go:914 +0x218
github.com/grafana/xk6-browser/common.(*screenshotter).fullPageSize(0x140050186e0, 0x1400231e9c0)
        github.com/grafana/xk6-browser@v1.3.0/common/screenshotter.go:105 +0xfc
github.com/grafana/xk6-browser/common.(*screenshotter).screenshotPage(0x14005018738?, 0x1400231e9c0, 0x14005018738)
        github.com/grafana/xk6-browser@v1.3.0/common/screenshotter.go:324 +0x2b8
github.com/grafana/xk6-browser/common.(*Page).Screenshot(0x1400231e9c0, {0x1020289b0, 0x140023e6ea0})
        github.com/grafana/xk6-browser@v1.3.0/common/page.go:1119 +0x29c
reflect.Value.call({0x101d62060?, 0x14000c872d0?, 0x14a3bb650?}, {0x1018afa59, 0x4}, {0x14000f1b080, 0x1, 0x0?})
        reflect/value.go:596 +0x994
reflect.Value.Call({0x101d62060?, 0x14000c872d0?, 0x140023e6ea0?}, {0x14000f1b080?, 0x140021779d0?, 0x10095f394?})
        reflect/value.go:380 +0x94
github.com/dop251/goja.(*Runtime).newWrappedFunc.(*Runtime).wrapReflectFunc.func1({{0x1020289b0, 0x140029b1080}, {0x140004949a0, 0x1, 0x1a}})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/runtime.go:1982 +0x2cc
github.com/dop251/goja.(*nativeFuncObject).vmCall(0x140003829c0, 0x14002437320, 0x1)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/func.go:563 +0x16c
github.com/dop251/goja.call.exec(0x2437320?, 0x14002437320)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:3366 +0x74
github.com/dop251/goja.(*vm).run(0x14002437320)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:582 +0x6c
github.com/dop251/goja.(*vm).runTryInner(0x14000ca73f0?)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:834 +0x58
github.com/dop251/goja.(*generator).step(0x14000c248c0)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/func.go:762 +0x30
github.com/dop251/goja.(*generator).nextThrow(0x14000c248c0, {0x101fa79e0, 0x14000b03cb0})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/func.go:815 +0x1f8
github.com/dop251/goja.(*asyncRunner).onRejected(0x14000c248c0, {{0x102028dd8, 0x102e27b00}, {0x14000969380, 0x1, 0x1}})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/func.go:697 +0xe0
github.com/dop251/goja.(*Runtime).callJobCallback(0x0?, 0x14a01c350?, {0x102028dd8?, 0x102e27b00?}, {0x14000969380?, 0x10015c800?, 0x14003efd588?})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/runtime.go:2878 +0x64
github.com/dop251/goja.(*Promise).reject.(*Runtime).triggerPromiseReactions.(*Runtime).newPromiseReactionJob.func1.1()
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/builtin_promise.go:213 +0xac
github.com/dop251/goja.(*vm).try(0x14002437320, 0x14003efd680)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:811 +0x1e0
github.com/dop251/goja.(*Promise).reject.(*Runtime).triggerPromiseReactions.(*Runtime).newPromiseReactionJob.func1()
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/builtin_promise.go:212 +0xc0
github.com/dop251/goja.(*Runtime).leave(0x14000eaa800)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/runtime.go:2751 +0xe0
github.com/dop251/goja.(*Runtime).runWrapped(0x14000eaa800, 0x103445878?)
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/runtime.go:2451 +0xf0
github.com/dop251/goja.AssertFunction.func1({0x0?, 0x0?}, {0x14000969360?, 0x0?, 0x0?})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/runtime.go:2401 +0x78
github.com/dop251/goja.(*Runtime).wrapPromiseReaction.func1({0x101dcc800?, 0x140010deec0?})
        github.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/builtin_promise.go:601 +0xa8
github.com/grafana/xk6-browser/k6ext.promise.func1.1()
        github.com/grafana/xk6-browser@v1.3.0/k6ext/promise.go:44 +0x4c
go.k6.io/k6/js/eventloop.(*EventLoop).Start(0x14002d66500, 0x14001084f00)
        go.k6.io/k6/js/eventloop/eventloop.go:177 +0x16c
go.k6.io/k6/js.(*VU).runFn.func2()
        go.k6.io/k6/js/runner.go:865 +0xe0
go.k6.io/k6/js/common.RunWithPanicCatching({0x10202d008?, 0x14000352800?}, 0x101d368a0?, 0x140027898c0?)
        go.k6.io/k6/js/common/util.go:86 +0x74
go.k6.io/k6/js.(*VU).runFn(0x14001764aa0, {0x102019c68, 0x140026c5a90}, 0x60?, 0x14001d82798, 0x14002218270, {0x140003379c0, 0x1, 0x1})
        go.k6.io/k6/js/runner.go:864 +0x1d8
go.k6.io/k6/js.(*ActiveVU).RunOnce(0x14000b5a000)
        go.k6.io/k6/js/runner.go:797 +0x3d4
go.k6.io/k6/lib/executor.ConstantVUs.Run.getIterationRunner.func7({0x102019c30, 0x14000f16180}, {0x102007818?, 0x14000b5a000?})
        go.k6.io/k6/lib/executor/helpers.go:81 +0x44
go.k6.io/k6/lib/executor.ConstantVUs.Run.func5({0x102013098, 0x14001764aa0})
        go.k6.io/k6/lib/executor/constant_vus.go:193 +0x284
created by go.k6.io/k6/lib/executor.ConstantVUs.Run in goroutine 165
        go.k6.io/k6/lib/executor/constant_vus.go:204 +0x708

Goja stack:

I’m using MacOS Ventura 13.3.1 Apple Mi Pro Chip 16GM Memory k6 v0.49.0 (go1.21.6, darwin/arm64)

Hi @armaaar , welcome to the community forum!

I think your error is definitely not the same, because your error happens in the page.Screenshot function, and the previous script doesn’t even call screenshot. I assume your script calls screenshot(). Can you share the script and the html page with us?

Thanks.

You are absolutely correct! I didn’t notice the screenshot part. I’ve removed it and I’m running the tests again. Hopefully they would be fixed now.

Here is a sanetized version of the script I was running when I got the error:

export function setup() {
    return getAccessToken()
}

export default async function (accessToken) {
    const tags = exec.vu.metrics.tags

    const browserContext = browser.newContext()
    browserContext.addCookies([{ name: 'access_token', value: accessToken, tags.url }])
    const page = browserContext.newPage()

    try {
        // Send request to server
        const response = await page.goto(tags.url)

        // Wait for page to load
        await page.waitForNavigation({waitUntil: 'load'})

        // Wait for all loaders to disappear
        page.waitForSelector('.loader', {state: 'detached', strict: false})

    } finally {
        check(page, { 'No Loaders': p => p.isHidden('.loader', {strict: false}) })

        page.screenshot({ path: `./screenshots/${tags.page}.png`, fullPage: true});
        page.close()
        browserContext.close()
    }
}