quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Hang on non-existent worker source

Open renatahodovan opened this issue 1 year ago • 1 comments

When creating a Worker with a non-existent source, qjs throws a ReferenceError, but instead of exiting, it just hangs forever. I'm not familiar with the standard, but this seems like unexpected behavior.

Test case:

var worker = new os.Worker("nonexistent.js");
worker.onmessage = function (e) {};

Build: CONFIG_CLANG=y make qjs Run: ./qjs --std test.js Git version: d378a9f

Backtrace from the hang:

reni@fuzzer1:~/work/sut/quickjs $ lldb -- ./qjs --std test.js
(lldb) target create "./qjs"
Current executable set to '/home/reni/work/sut/quickjs/qjs' (x86_64).
(lldb) settings set -- target.run-args  "--std" "test.js"
(lldb) r
Process 3041495 launched: '/home/reni/work/sut/quickjs/qjs' (x86_64)
ReferenceError: could not load module filename 'nonexistent.js'

Process 3041495 stopped
* thread #1, name = 'qjs', stop reason = signal SIGSTOP
    frame #0: 0x00007ffff7da463d libc.so.6`__GI___select(nfds=6, readfds=0x00007fffffffd9e0, writefds=0x00007fffffffda70, exceptfds=0x0000000000000000, timeout=0x0000000000000000) at select.c:69:11
(lldb) bt
* thread #1, name = 'qjs', stop reason = signal SIGSTOP
  * frame #0: 0x00007ffff7da463d libc.so.6`__GI___select(nfds=6, readfds=0x00007fffffffd9e0, writefds=0x00007fffffffda70, exceptfds=0x0000000000000000, timeout=0x0000000000000000) at select.c:69:11
    frame #1: 0x000055555560a338 qjs`js_os_poll(ctx=0x0000555555667d60) at quickjs-libc.c:2368:11
    frame #2: 0x0000555555607332 qjs`js_std_loop(ctx=0x0000555555667d60) at quickjs-libc.c:3981:30
    frame #3: 0x00005555555673d5 qjs`main(argc=3, argv=0x00007fffffffdf08) at qjs.c:522:9
    frame #4: 0x00007ffff7cb2d90 libc.so.6`__libc_start_call_main(main=(qjs`main at qjs.c:300), argc=3, argv=0x00007fffffffdf08) at libc_start_call_main.h:58:16
    frame #5: 0x00007ffff7cb2e40 libc.so.6`__libc_start_main_impl(main=(qjs`main at qjs.c:300), argc=3, argv=0x00007fffffffdf08, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffdef8) at libc-start.c:392:3
    frame #6: 0x0000555555566805 qjs`_start + 37

renatahodovan avatar May 11 '24 14:05 renatahodovan

It works as designed i.e. the error happens while executing the module and if there is a "onmessage" handler on the worker the main loop keeps running. We could add a "onerror" handler to report errors so that it is possible to get notified. We could also stop the program if there is an error in a worker and if there is no "onerror" handler.

bellard avatar May 13 '25 09:05 bellard