### 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@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@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@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@bar:~# lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 11 (bullseye) Release: 11 Codename: bullseye foo@bar:~# uname -a Linux localhost 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux ```
I think this is a matter of the code imported from the duktape project for having jsmodule support, respectively `src/modules/app_jsdt/duk_module_node.{c,h}`. I see function names referring to cache, so the js modules might be cached and used from there. If it is something that has to be done there, it has to be addressed to the duktape project, because Kamailio just reuses the code as recommended by duktape project, embedding the code, but there is no plan to diverge our copy from the original one, we sycn from time to time with the upstream version.
Maybe @xantek-imc can comment more.
This issue is stale because it has been open 6 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.
Closed #3145 as not planned.