k6
k6 copied to clipboard
gRPC testing causes panic
Brief summary
So I was trying out the grpc testing with insecure option. And running the test causes panic
rgao@rgao-mac js % k6 run test.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: test.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
ERRO[0000] panic: runtime error: invalid memory address or nil pointer dereference
goroutine 31 [running]:
runtime/debug.Stack()
runtime/debug/stack.go:24 +0x68
go.k6.io/k6/js/common.RunWithPanicCatching.func1()
go.k6.io/k6/js/common/util.go:102 +0x150
panic({0x101355a80, 0x101ddfb90})
runtime/panic.go:838 +0x204
github.com/dop251/goja.AssertFunction.func1.1()
github.com/dop251/[email protected]/runtime.go:2305 +0x84
panic({0x101355a80, 0x101ddfb90})
runtime/panic.go:838 +0x204
github.com/dop251/goja.(*vm).try.func1()
github.com/dop251/[email protected]/vm.go:537 +0x590
panic({0x101355a80, 0x101ddfb90})
runtime/panic.go:838 +0x204
go.k6.io/k6/js/modules/k6/grpc.(*Client).Invoke(0x14000e0f470, {0x140001b7110, 0x2d}, {0x0, 0x0}, 0x10067bdec?)
go.k6.io/k6/js/modules/k6/grpc/client.go:161 +0x118
reflect.Value.call({0x1013e5100?, 0x14000e0f470?, 0x1022f0108?}, {0x100ffa87d, 0x4}, {0x14001bda1e0, 0x3, 0x100c4e2a0?})
reflect/value.go:556 +0x5e4
reflect.Value.Call({0x1013e5100?, 0x14000e0f470?, 0x1400264af90?}, {0x14001bda1e0, 0x3, 0x3})
reflect/value.go:339 +0x98
github.com/dop251/goja.(*Runtime).wrapReflectFunc.func1({{0x1014bebb8, 0x14000e0f4a0}, {0x14000e164e0, 0x1, 0x6}})
github.com/dop251/[email protected]/runtime.go:1891 +0x150
github.com/dop251/goja.(*vm)._nativeCall(0x14000ab0000, 0x14000f8e0a0, 0x1)
github.com/dop251/[email protected]/vm.go:2737 +0x1f8
github.com/dop251/goja.call.exec(0xab0000?, 0x14000ab0000)
github.com/dop251/[email protected]/vm.go:2709 +0x92c
github.com/dop251/goja.(*vm).run(0x14000ab0000)
github.com/dop251/[email protected]/vm.go:408 +0x9c
github.com/dop251/goja.(*baseJsFuncObject)._call(0x14000e78820, {{0x1014bf408, 0x101e2f460}, {0x14002728ab0, 0x1, 0x1}}, {0x0?, 0x0}, {0x1014bebb8?, 0x14000d8c090?})
github.com/dop251/[email protected]/func.go:193 +0x394
github.com/dop251/goja.(*arrowFuncObject).Call(0x14000dbd498?, {{0x1014bf408, 0x101e2f460}, {0x14002728ab0, 0x1, 0x1}})
github.com/dop251/[email protected]/func.go:160 +0x4c
github.com/dop251/goja.AssertFunction.func1.2()
github.com/dop251/[email protected]/runtime.go:2310 +0x6c
github.com/dop251/goja.(*vm).try(0x14000dbd5f8?, 0x100643aa0?)
github.com/dop251/[email protected]/vm.go:545 +0x108
github.com/dop251/goja.AssertFunction.func1({0x1014bf408?, 0x101e2f460?}, {0x14002728ab0?, 0x1?, 0x1?})
github.com/dop251/[email protected]/runtime.go:2309 +0xb8
go.k6.io/k6/js.(*VU).runFn.func1.1()
go.k6.io/k6/js/runner.go:800 +0x54
go.k6.io/k6/js/eventloop.(*EventLoop).Start(0x14000d86140, 0x14000f11ef0)
go.k6.io/k6/js/eventloop/eventloop.go:112 +0x134
go.k6.io/k6/js.(*VU).runFn.func1()
go.k6.io/k6/js/runner.go:799 +0xe8
go.k6.io/k6/js/common.RunWithPanicCatching({0x1014bfd60?, 0x14000451650?}, 0x14000dbd898?, 0x1006060d0?)
go.k6.io/k6/js/common/util.go:106 +0x78
go.k6.io/k6/js.(*VU).runFn(0x14000e2c820, {0x1014b7120, 0x140000dba40}, 0xe0?, 0x1400000fe48, 0x14002728aa0, {0x14002728ab0, 0x1, 0x1})
go.k6.io/k6/js/runner.go:798 +0x208
go.k6.io/k6/js.(*ActiveVU).RunOnce(0x140000dba00)
go.k6.io/k6/js/runner.go:750 +0x36c
go.k6.io/k6/lib/executor.getIterationRunner.func1({0x1014b71c8, 0x14000f11bc0}, {0x1014ae368?, 0x140000dba00?})
go.k6.io/k6/lib/executor/helpers.go:144 +0x50
go.k6.io/k6/lib/executor.PerVUIterations.Run.func5({0x1014b3190, 0x14000e2c820})
go.k6.io/k6/lib/executor/per_vu_iterations.go:243 +0x36c
created by go.k6.io/k6/lib/executor.PerVUIterations.Run
go.k6.io/k6/lib/executor/per_vu_iterations.go:256 +0x99c
Goja stack:
native
running (00m00.3s), 0/1 VUs, 0 complete and 1 interrupted iterations
default ✗ [======================================] 1 VUs 00m00.3s/10m0s 1/1 iters, 1 per VU
WARN[0000] No script iterations finished, consider making the test duration longer
data_received........: 9 B 31 B/s
data_sent............: 42 B 146 B/s
iteration_duration...: avg=285.6ms min=285.6ms med=285.6ms max=285.6ms p(90)=285.6ms p(95)=285.6ms
iterations...........: 1 3.466217/s
ERRO[0000] a panic occurred during JS execution: runtime error: invalid memory address or nil pointer dereference
k6 version
Latest (v0.39.0)
OS
mac os 12.1
Docker version and image (if applicable)
N/A
Steps to reproduce the problem
import grpc from 'k6/net/grpc';
import { check, sleep } from 'k6';
const client = new grpc.Client();
client.load([], 'greeter.proto');
export const options = {
insecureSkipTLSVerify: true,
};
export default () => {
client.connect('domain:port', {
plaintext: true
});
const response = client.invoke('some_grpc_request');
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});
console.log(JSON.stringify(response.message));
client.close();
sleep(1);
};
Panic is raised during client.invoke
Expected behaviour
Test doesn't raise panic
Actual behaviour
Test raises panic
Thanks for opening this issue! I think the problem is that you are not actually passing the second parameter to client.Invoke(), which is supposed to be the request. So we essentially get a nil but we try to marshal it to JSON and result in a panic: https://github.com/grafana/k6/blob/e09bb87277865d668586429eee97158fbbfc58e5/js/modules/k6/grpc/client.go#L161
So yeah, the script is slightly wrong, but this should certainly not cause k6 to panic, so it's a very valid bug - k6 should just throw an exception at that point. The fix is simple enough, we should just add that check (and a test), do you want to make a PR?
Thank you so much for the reply. Sure i'll arrange some time adding the check, should be quite straightforward but I need some time to read thru the code
Hi @na-- , I am a student who needs to contribute to an OpenSource project in my coursework, so I was wondering if you can assign this to me. This issue seems to be a good initiation of my journey towards contribution to FOSS projects. Can you please assign this to me?
@c47gao, you haven't indicated that you have started work on this or that you are about to make a PR, so I don't see a reason why @theshashankpal can't work on it? @theshashankpal, I will assign it to you, in case that is a requirement for your course, but in general we don't assign issues to external contributors - you can just start working on it after a consensus is reached on how to implement something.