[sr-dev] [kamailio/kamailio] RPC command app_jsdt.reload does not reload "require()" files (Issue #3145)

Vincent Handfield notifications at github.com
Tue Jun 14 18:46:36 CEST 2022


### Description

If the file loaded with the modparam "load" uses CommonJS modules (Issue #3037-PR #3038), the modules are not reloaded when issuing the command app_jsdt.reload. Only the "main" file is reloaded.

#### Reproduction

1 - Start Kamailio with those files as the initial configuration

```generic
# kamailio.cfg
## Only the part concerning app_jsdt is included. 
## The rest of the config file is ommited for the sake of clarity

loadmodule "app_jsdt.so"
modparam("app_jsdt", "load", "/etc/kamailio/js/index.js")
modparam("app_jsdt", "mode", 1)
cfgengine "jsdt"
```

```js
// index.js
var myModule = require('./myModule');

function ksr_request_route() {
    myModule.myFunction()
    KSR.log("info", "KSR.log called from the index.js file");
}
```

```js
// myModule.js
exports.myFunction = function() {
    KSR.log("info", "KSR.log called from the myModule.js file"
}
```

2 - Modify the myModule.js file

```js
// myModule.js
exports.myFunction = function() {
    KSR.log("info", "KSR.log called from the MODIFIED myModule.js file"
}
```

3 - Run the reload command

  ```console
  foo at bar:~# kamcmd app_jsdt.reload
  {
          old: 0
          new: 1
  }
  ```

> Log file
>
> INFO: app_jsdt [app_jsdt_api.c:1557]: app_jsdt_rpc_reload(): marking for reload js script file: /etc/kamailio/js/index.js (0 => 0)
> DEBUG: app_jsdt [app_jsdt_api.c:534]: jsdt_kemi_reload_script(): reloading js script file: /etc/kamailio/js/index.js (0 => 1)
  
4 - The log file still show those lines:

> Log file
>
>INFO    <core> [core/kemi.c:156]: sr_kemi_core_log(): KSR.log called from the myModule.js file
>INFO    <core> [core/kemi.c:156]: sr_kemi_core_log(): KSR.log called from the index.js file

5 - Modify the index.js file

```js
// index.js
var myModule = require('./myModule');

function ksr_request_route() {
    myModule.myFunction()
    KSR.log("info", "KSR.log called from the MODIFIED index.js file");
}
```

6 - Run the reload command

```console
foo at bar:~# kamcmd app_jsdt.reload
{
        old: 1
        new: 2
}
```

> Log file
>
> INFO: app_jsdt [app_jsdt_api.c:1557]: app_jsdt_rpc_reload(): marking for reload js script file: /etc/kamailio/js/index.js (0 => 1)
> DEBUG: app_jsdt [app_jsdt_api.c:534]: jsdt_kemi_reload_script(): reloading js script file: /etc/kamailio/js/index.js (1 => 2)

7 - The log file now show those lines:

> Log file
>
> INFO    <core> [core/kemi.c:156]: sr_kemi_core_log(): KSR.log called from the myModule.js file
> INFO    <core> [core/kemi.c:156]: sr_kemi_core_log(): KSR.log called from the MODIFIED index.js file

8 - Restart kamailio completly

9 - The log file now show those lines:

> Log file
>
> INFO    <core> [core/kemi.c:156]: sr_kemi_core_log(): KSR.log called from the MODIFIED myModule.js file
> INFO    <core> [core/kemi.c:156]: sr_kemi_core_log(): KSR.log called from the MODIFIED index.js file

### Possible Solutions

Sorry, I would really like to provide one, but, as I'm a new Kamailio user, I don't know all the internals yet.

### Additional Information

* **Kamailio Version**

```console
foo at bar:~# kamailio -v
version: kamailio 5.6.0 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 10.2.1
```

* **Operating System**:

```console
foo at bar:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye
foo at bar:~# uname -a
Linux localhost 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux
```


-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3145
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/3145 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20220614/392af196/attachment.htm>


More information about the sr-dev mailing list