Issue with duktape

Hello all!

I’m a bit flustered. I inherited an environment that use janus in conjunction with duktape + javascript plugin, and the previous maintainer can’t provide me help. I’ve been tasked with updating the codebase since we are starting to see some instability. For now, I’m trying to upgrade to version 0.13.3
I manage to build the service and start it, but I get a few errors popping up in the log :

The context

Version running : 0.11.6
Target version : 0.13.3
OS : Ubuntu 22.04 / Ubuntu 20.04. Willing to change the version to a specific one if there’s any issues.

We build our janus machines on Ubuntu VMs on the cloud.
We first build a docker file for a base build, and then use an install script to pull the repo with the useful scripts and the base build.
We run this command
docker run --rm -v "/janus-update/janus-gateway":"/src" -v "/opt/janus":"/opt/janus" -v "/usr":"/hostusr" -w "/src" --name="janus-base-build" <image tag> /bin/bash -c "sh ./Scripts/build.sh"
And lastly, we start + enable janus-gateway

The problems

First error showing up :

vroom.js  Module loaded
[ERR] [plugins/janus_vroom.c:janus_vroom_init:1733] Error loading JS script /opt/janus/share/janus/vroom/vroom.js: SyntaxError: unterminated statement (line 414, end of input) (at 
[WARN] The 'janus.plugin.vroom' plugin could not be initialized

Thing I don’t totally get : the file vroom.js stops at line 339, so checking what is at line 414 is only possible for my 5th dimension homologue.

My best guess is that the evaluation done in C with duktape changes the files during initialization. I’ve made sure that all lines were correctly terminated with semicolumns (some weren’t). Still, after I rebuilt the service, it still gives me the same error. Anyone else found themselves facing this specific problem?

Second error

Might be due to the first, might not :

Loading plugin 'libjanus_duktape.so'...
[ERR] [janus.c:main:5495] Couldn't load plugin 'libjanus_duktape.so': /opt/janus/lib/janus/plugins/libjanus_duktape.so: undefined symbol: duk_eval_raw

This one seems to be a file built during the installation script, and I don’t have a file with an identical name. The closest I have is janus_duktape.c, which is in the /plugin/ folder. However, there are no direct calls to duk_eval_raw in the file ; it is defined in duktape.c, and used in duktape.h.

Third error

Finally, and this one I think is less of a problem :

[ERR] [plugins/janus_lua.c:janus_lua_init:1422] Error loading Lua script /opt/janus/share/janus/lua/echotest.lua: /opt/janus/share/janus/lua/echotest.lua:6: module 'json' not found: 
no field package.preload['json'] 
no file '/usr/local/share/lua/5.3/json.lua' 
no file '/usr/local/share/lua/5.3/json/init.lua'
no file [... you get the idea...]
[WARN] The 'janus.plugin.lua' plugin could not be initialized

This one I care a bit less about, since we’re not using Lua. I was looking for a way to disable it in the documentation, but couldn’t find any. Maybe I missed it, since I’ve been working on the same issue since Monday and must admit, I’m getting a bit frustrated. I’m sure you get it :slight_smile:
[EDIT BEFORE SENDING : Just noticed --enable-plugin-lua as an argument in build.sh. Guessed this would take care of things, but the logs still shows the same after doing that. :frowning: )
But anyway, I’m pretty sure this is linked to the issue I’m having with duktape.

I don’t know which information would help to provide me with the information / tip that’ll make me realize what the problem is, so for now I’ll leave it at that.

Thanks for reading, and another thanks if you’re willing to contribute your knowledge to help me retain my sanity!

janus.plugin.vroom is not something we provide: sounds like your employer wrote a custom JavaScript file to use with the duktape plugin. On the failure to build, notice we now use duktape as a dependency and don’t embed it anymore, so you have to install it externally and have it found by the configure.

1 Like

Yes, it is indeed our plugin. However, I don’t know (yet) any of the intricacies of Duktape. Heck, I don’t really know how it works, hence why I’m unsure if it is normal to see the error on a line that doesn’t exist in the codebase. For now, I’m assuming that the code gets reworked backscene and then sent to the compiler.

As for duktape, indeed, I encountered that issue the first time I tried to update janus, and solved it doing two steps (maybe I did something wrong there?) :

  1. I made sure that references to duktape in the new codebase pointed to where the duktape files were in the source code for the build.

  2. I added duktape to be installed in the environment in the dockerfile.

I’m all new to this, and haven’t coded in C for a few years, so I’m sorry if there’s something quite obvious that I’m missing, but just to be clear, in our case, the following files :

  • duk_config.h
  • duk_console (.c / .h)
  • duk_module_duktape (.c / .h)
  • duktape (.c / .h)
  • (also : duk_source_meta.json, though this one isn’t referenced to directly)

were included in the source code. Does the fact that it is now a dependency mean that these files should be referenced to as any other system package (include it and let it be detected automatically) - and thus should not reference those files anymore?

duktape.c, duktape.h, duk_config.h and duk_source.meta.json are not part of our repo anymore. If they’re still there, you may want to start from a clean setup. We got rid of them here.

1 Like

post deleted
just realized that the files left are not the ones that were deleted. TGIF.

After some fiddling, I’m starting to understand the whole thing a bit better! As per your suggestion, I rebuilt the whole thing, importing the added code to it carefully, and that was a bit educational.

But now I’m stuck somewhere else. If anyone got a few minutes to check this and tell me their gut feeling, I’d be grateful.

The log gives the whole problem : my plugin file can’t be loaded.

So far, the only fix I tried is this : even though the log showed the correct directory for the plugins, I created a “vroom.conf” in /etc/ld.so.conf.d/ to be sure that ldopen() finds the directory. Did not work.
I’ve been reading

Finally, I still have that problem that crops up about the Lua plugin : even though I set the ./Configuration thusly :

./configure \
  --prefix=/opt/janus \
  --disable-all-plugins \
  --disable-all-transports \
  --disable-all-handlers \
  --enable-rest=yes \
  --enable-websockets=yes \
  --enable-websockets-event-handler=yes \
  --disable-turn-rest-api \
  --enable-plugin-duktape=yes\
  --enable-plugin-vroom=yes \
  --enable-json-logger=yes \
  --disable-docs \
  --enable-post-processing=yes && \
  make && make install && make configs && ldconfig

While it doesn’t bother me that much, I wonder if it is associated to the problem at hand.
Anyway, I’m going back to it. Thanks for your time.

Log :

Plugins folder : /opt/janus/lib/janus/plugins
[WARN] Plugin 'libjanus_echotest.so' has been disabled, skipping...
Loading plugin 'libjanus_vroom.so'...
[ERR] [janus.c:main:5495] Couldn't load plugin 'libjanus_vroom.so': libduktape.so.207: cannot open shared object file: No such file or directory
[WARN] Plugin 'libjanus_audiobridge.so' has been disabled, skipping...
[WARN] Plugin 'libjanus_recordplay.so' has been disabled, skipping...
[WARN] Plugin 'libjanus_videocall.so' has been disabled, skipping...
[WARN] Plugin 'libjanus_sip.so' has been disabled, skipping...
[WARN] Plugin 'libjanus_nosip.so' has been disabled, skipping...
[WARN] Plugin 'libjanus_voicemail.so' has been disabled, skipping...
Loading plugin 'libjanus_duktape.so'...
Sessions watchdog started
Joining Janus requests handler thread
[ERR] [janus.c:main:5495] Couldn't load plugin 'libjanus_duktape.so': /opt/janus/lib/janus/plugins/libjanus_duktape.so: undefined symbol: duk_eval_raw

/opt/janus/lib/janus/plugins :

> ls -l | grep vroom
-rwxr-xr-x 1 root root    1025 Apr 25 14:54 libjanus_vroom.la
lrwxrwxrwx 1 root root      23 Apr 25 14:54 libjanus_vroom.so -> libjanus_vroom.so.0.0.0
lrwxrwxrwx 1 root root      23 Apr 25 14:54 libjanus_vroom.so.0 -> libjanus_vroom.so.0.0.0
-rwxr-xr-x 1 root root  633768 Apr 25 14:54 libjanus_vroom.so.0.0.0

I have no idea what this is, but this is not a Janus plugin. When you use the Duktape plugin with a custom script, you still load libjanus_duktape.so as the shared object: in the configuration file you then tell the Duktape plugin which JavaScript file it should load (and this is where you put a link to your js file).

This is more relevant, since there’s an undefined symbol. Maybe you installed the Duktape library (that the plugin now externally depends on) in a non-standard folder and so the plugin can’t find it. You can try doing an ldd /opt/janus/lib/janus/plugins/libjanus_duktape.so to see which dependencies it can’t find, so that you can work on fixing that.

1 Like

Sorry, I guess I never stated this and it is my bad. janus_vroom is our plugin, which - from what I saw by rebuilding the project - is just a modified version of janus_ducktape with a few added variables and methods, which are reflected in the javascript file. But thanks for the ‘ldd’ tip :

> ldd /opt/janus/lib/janus/plugins/libjanus_duktape.so
        linux-vdso.so.1 (0x00007ffd3bba0000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fc67533a000)
        libjansson.so.4 => /lib/x86_64-linux-gnu/libjansson.so.4 (0x00007fc67532a000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc675102000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fc67508c000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc674fa5000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc67549e000)

> ldd /opt/janus/lib/janus/plugins/libjanus_vroom.so
        linux-vdso.so.1 (0x00007fff1dd6c000)
        libduktape.so.207 => not found
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f9f3151e000)
        libjansson.so.4 => /lib/x86_64-linux-gnu/libjansson.so.4 (0x00007f9f3150e000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9f312e6000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f9f31270000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9f31187000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f9f31684000)

I don’t know if anything’s weird for janus_ducktape, but clearly something is wrong with my plugin (libduktape.so.207 => not found). I’ll look into that from here, that’s a good tip.

I found the file, it is in the docker image I’ve built. Meaning, I probably have a different version on the computer than the one I need, which is most likely built in my base image. Thanks, you rock Lorenzo. I’m getting right on that.

Hello, bothering you again.
I still get the “unterminated statement”, at a end of input. By fiddling a bit around with duktape itself, I found that depending on the type of error, there could be other information in the stack trace. For example :

duk> {test: "foo
SyntaxError: unterminated string (line 1, end of input)
    at [anon] (input:1) internal
    at [anon] (duk_lexer.c:943) internal
duk> {test: "foo"
SyntaxError: parse error (line 1, end of input)
    at [anon] (input:1) internal
    at [anon] (duk_js_compiler.c:3797) internal
duk> {"test":"foo"}
SyntaxError: unterminated statement (line 1)
    at [anon] (input:1) internal
    at [anon] (duk_js_compiler.c:6826) internal

Any tip on how to debug this? Is there perhaps some option to get the whole stack trace on a duktape error, so I could laser down on the duktape function creating that error.

If not, well, I’m gonna keep prodding. If I find anything pertinent to the community, I’ll post it here.

Not sure, but it looks like you’re trying to use JSON objects as JavaScript commands, or a code block.

I found the issue.
Of course, it was a stupid one. As is often the case (with me anyway) :
There was indeed a problem in my code, probably due to a bad copy-paste between my scratchpad and my IDE : a missing }.

HOWEVER :

the missing character wasn’t in the file that was being shown in the logs, but in janus-sdp.js. So if you’re a future reader and having an issue with your plugin, and you get a log from duktape about your <plugin.js>, also check the janus-sdp file! Might be there.