Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

panic: interface conversion: interface is nil, not goja.Value #417

Closed
sniku opened this issue Jun 27, 2022 · 4 comments · Fixed by #425
Closed

panic: interface conversion: interface is nil, not goja.Value #417

sniku opened this issue Jun 27, 2022 · 4 comments · Fixed by #425
Assignees
Labels
bug Something isn't working next Might be eligible for the next planning (not guaranteed!)
Milestone

Comments

@sniku
Copy link
Collaborator

sniku commented Jun 27, 2022

xk6-browser panics with the attached script.
version: latest main eb13672

The panic is reproducible on my machine. It happened 4 times in the row.

➜  Downloads xk6-browser3 run reproducible-websocket-EOF-errors.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: reproducible-websocket-EOF-errors.js
     output: -

  scenarios: (100.00%) 1 scenario, 10 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 10 looping VUs for 10m0s (gracefulStop: 30s)

[...]
ERRO[0030] err:websocket: close 1006 (abnormal closure): unexpected EOF  category="Connection:handleIOError" elapsed="0 ms" goroutine=209
ERRO[0030] cmd.Wait: signal: killed                      category="BrowserType:execute" elapsed="2 ms" goroutine=23
ERRO[0030] stdout.Close: close |0: file already closed   category="BrowserType:execute" elapsed="0 ms" goroutine=23
panic: interface conversion: interface is nil, not goja.Value
running (00m30.0s), 10/10 VUs, 22 complete and 0 interrupted iterations
goroutine 4320 [running]:------------------------] 10 VUs  00m30.0s/10m0s
github.com/grafana/xk6-browser/common.(*ElementHandle).waitForElementState(0xc000deb060?, {0x1687188, 0xc00372d500}, {0xc003b31530, 0x3, 0x3}, 0x6fc23ac00)
	github.com/grafana/[email protected]/common/element_handle.go:660 +0x145
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func1({0x1687188, 0xc00372d500}, 0xc000deb060)
	github.com/grafana/[email protected]/common/element_handle.go:1371 +0x105
github.com/grafana/xk6-browser/common.retryPointerAction({0x1687188, 0xc00372d500}, 0xc00022e460, 0xc00372d4a0)
	github.com/grafana/[email protected]/common/element_handle.go:1460 +0x165
github.com/grafana/xk6-browser/common.(*ElementHandle).newPointerAction.func2({0x1687188?, 0xc00372d500?}, 0x0?, 0xc001271fb0?)
	github.com/grafana/[email protected]/common/element_handle.go:1437 +0x4b
created by github.com/grafana/xk6-browser/common.callApiWithTimeout
	github.com/grafana/[email protected]/common/helpers.go:121 +0x17b
➜  Downloads 

import { check } from 'k6';
import launcher from 'k6/x/browser';

export let options = {
  vus: 10,
  duration: '1m'

} 

export default function () {
  const browser = launcher.launch('chromium', {
    headless: false,
  });
  const context = browser.newContext();
  const page = context.newPage();

  // Goto front page, find login link and click it
  page.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
  const elem = page.$('a[href="/my_messages.php"]');
  elem.click();
  page.waitForLoadState();

  // Enter login credentials and login
  page.$('input[name="login"]').type('admin');
  page.$('input[name="password"]').type('123');
  page.$('input[type="submit"]').click();

  // We expect the above form submission to trigger a navigation, so wait for it
  // and the page to be loaded.
  page.waitForNavigation();

  check(page, {
    'header': page.$('h2').textContent() == 'Welcome, admin!',
  });

  page.close();
  browser.close();
}
panic-2022-06-27_16.32.27.mp4
@sniku sniku added the bug Something isn't working label Jun 27, 2022
@imiric imiric added the next Might be eligible for the next planning (not guaranteed!) label Jun 27, 2022
@inancgumus
Copy link
Member

inancgumus commented Jun 27, 2022

A temporary fix seems easy, but the error points out a race condition issue.

value := result.(goja.Value)

-  value := result.(goja.Value) 
+  value, ok := result.(goja.Value)
+  if !ok {
+    ...
+  }

@imiric
Copy link
Contributor

imiric commented Jun 28, 2022

Yeah, definitely caused by a race condition, but we shouldn't crash because of it, so always checking type assertions is the safe thing to do.

@inancgumus If you're planning to work on this, could you also do that change in all other places we assume a goja.Value? A helper function is probably a good idea.

@inancgumus inancgumus self-assigned this Jun 28, 2022
@inancgumus inancgumus added this to the v0.4.0 milestone Jun 28, 2022
inancgumus added a commit that referenced this issue Jun 30, 2022
This commit properly type asserts and removes nolint directives. There
are new helpers to reduce code bloat and possible error messages
refactoring work:
+ asGojaValue: returns a given value as a goja value or panics.
+ gojaValueToString: returns a given a value as string or panics.

This commit also refactors tests to remove nolint directives.

Fixes: #417
@inancgumus
Copy link
Member

inancgumus commented Jun 30, 2022

I noticed in #425 that we mostly are going to crash when the type assertion fails 😒 At least, we'll say: hey, there is a type-mismatch. #142's time is approaching.

inancgumus added a commit that referenced this issue Jun 30, 2022
This commit properly type asserts and removes nolint directives. There
are new helpers to reduce code bloat and possible error messages
refactoring work:
+ asGojaValue: returns a given value as a goja value or panics.
+ gojaValueToString: returns a given a value as string or panics.

This commit also refactors tests to remove nolint directives.

Fixes: #417
@inancgumus
Copy link
Member

inancgumus commented Jul 5, 2022

@sniku, before the fix, we were seeing the following errors:

...
panic: interface conversion: interface is nil, not goja.Value
...

After the fix, I rerun the script you shared, and we no longer get any of these errors. However, we still get the usual race condition errors as follows:

ERRO[0047] cannot query element for selector ("input[name=\"login\"]"): element handle cannot evaluate: cannot call function on expression ("\n\t\t(node, injected, selector) => {\n\t\t\treturn injected.querySelector(selector, node || document, false);\n\t\t}\n\t\n//# sourceURL=__xk6_browser_evaluation_script__\n") in execution context (3) in frame (8741591778908D9C86DDDB08002A6325) with session (1182CE87F40D061C621471FF52104A2D): Cannot find context with specified id (-32000)
        at reflect.methodValueCall (native)
        at file:///Users/inanc/grafana/xk6-browser/examples/pawel.js:24:2(49)
        at native  executor=constant-vus scenario=default source=stacktrace

The error above is not about this issue; we'll address race condition issues in #428 and #427.

inancgumus added a commit that referenced this issue Jul 7, 2022
This commit properly type asserts and removes nolint directives. There
are new helpers to reduce code bloat and possible error messages
refactoring work:
+ asGojaValue: returns a given value as a goja value or panics.
+ gojaValueToString: returns a given a value as string or panics.

This commit also refactors tests to remove nolint directives.

Fixes: #417
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working next Might be eligible for the next planning (not guaranteed!)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants