<!--
Kamailio Project uses GitHub Issues only for bugs in the code or feature requests.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list
* http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
If you submit a feature request (or enhancement), you can delete the text of the template and only add the description of what you would like to be added.
If there is no content to be filled in a section, the entire section can be removed.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment). -->
### Description event_callback for app_lua is not working
### Troubleshooting
#### Reproduction # ----- app_lua params ---- 1. load the htable and app_lua with following parameters modparam("app_lua", "reload", 1) modparam("app_lua", "load", "/usr/local/etc/kamailio/route.lua") modparam("htable", "event_callback", "ksr_htable_event")
-- event callback function implemented in Lua function ksr_htable_event(evname) KSR.info("===== htable module triggered event: " .. evname .. "\n"); return 1; end
#### Debugging Data May 3 12:15:19 ip-172-31-4-160 kamailio[9797]: ERROR: app_lua [app_lua_api.c:652]: app_lua_run_ex(): lua loading state not initialized (call: ksr_htable_event)
``` (paste your debugging data here) ```
#### Log Messages
``` May 3 12:15:19 ip-172-31-4-160 kamailio[9797]: ERROR: app_lua [app_lua_api.c:652]: app_lua_run_ex(): lua loading state not initialized (call: ksr_htable_event) ```
#### SIP Traffic
<!-- If the issue is exposed by processing specific SIP messages, grab them with ngrep or save in a pcap file, then add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site). -->
``` (paste your sip traffic here) ```
### Possible Solutions
<!-- If you found a solution or workaround for the issue, describe it. Ideally, provide a pull request with a fix. -->
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` root@ip-172-31-4-160:/usr/local/etc/kamailio# kamailio -v version: kamailio 5.1.3 (x86_64/linux) flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, 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_BLACKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, 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 on 15:16:50 Apr 24 2018 with gcc 4.8.4 ```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `uname -a`) -->
``` root@ip-172-31-4-160:/usr/local/etc/kamailio# uname -a Linux ip-172-31-4-160 3.13.0-143-generic #192-Ubuntu SMP Tue Feb 27 10:45:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux ```
Can you do `kamctl ps` and paste here the description for PID 9797 (or the one that prints the error, if you have to test and reproduce with a new kamailio instance)?
May 3 12:45:53 ip-172-31-4-160 kamailio[9982]: ERROR: app_lua [app_lua_api.c:652]: app_lua_run_ex(): lua loading state not initialized (call: ksr_htable_event)
{"jsonrpc":"2.0","result":[{"IDX":0,"PID":9982,"DSC":"main process - attendant"},{"IDX":1,"PID":9983,"DSC":"udp receiver child=0 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":2,"PID":9984,"DSC":"udp receiver child=1 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":3,"PID":9985,"DSC":"udp receiver child=2 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":4,"PID":9986,"DSC":"udp receiver child=3 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":5,"PID":9987,"DSC":"udp receiver child=4 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":6,"PID":9988,"DSC":"udp receiver child=5 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":7,"PID":9989,"DSC":"udp receiver child=6 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":8,"PID":9990,"DSC":"udp receiver child=7 sock=172.31.4.160:5060 (13.57.122.212:5060)"},{"IDX":9,"PID":9991,"DSC":"slow timer"},{"IDX":10,"PID":9992,"DSC":"timer"},{"IDX":11,"PID":9993,"DSC":"secondary timer"},{"IDX":12,"PID":9994,"DSC":"JSONRPCS FIFO"},{"IDX":13,"PID":9995,"DSC":"JSONRPCS DATAGRAM"},{"IDX":14,"PID":9996,"DSC":"tcp main process"}],"id":10008}
@miconda do we need to check something else also?
0(10321) DEBUG: app_lua [app_lua_sr.c:1979]: lua_sr_kemi_register_libs(): exporting KSR.htable.sht_lock(...) 0(10321) DEBUG: app_lua [app_lua_sr.c:1979]: lua_sr_kemi_register_libs(): exporting KSR.htable.sht_unlock(...) 0(10321) DEBUG: app_lua [app_lua_sr.c:1979]: lua_sr_kemi_register_libs(): exporting KSR.htable.sht_reset(...) 0(10321) DEBUG: app_lua [app_lua_sr.c:1979]: lua_sr_kemi_register_libs(): exporting KSR.htable.sht_iterator_start(...) 0(10321) DEBUG: app_lua [app_lua_sr.c:1979]: lua_sr_kemi_register_libs(): exporting KSR.htable.sht_iterator_next(...) 0(10321) DEBUG: app_lua [app_lua_sr.c:1979]: lua_sr_kemi_register_libs(): exporting KSR.htable.sht_iterator_end(...) 0(10321) DEBUG: app_lua [app_lua_sr.c:1997]: lua_sr_kemi_register_libs(): initializing kemi sub-module: KSR.htable (htable) (6/17/232) 0(10321) DEBUG: app_lua [app_lua_sr.c:2000]: lua_sr_kemi_register_libs(): module 'KSR' has been initialized (18/232) 0(10321) DEBUG: app_lua [app_lua_sr.c:52]: lua_sr_probe(): someone probing from lua 0(10321) DEBUG: app_lua [app_lua_api.c:255]: lua_sr_init_probe(): Lua probe was ok! 0(10321) DEBUG: <core> [core/sr_module.c:942]: init_mod_child(): idx 0 rank -127: dispatcher [main] 0(10321) DEBUG: <core> [core/sr_module.c:942]: init_mod_child(): idx 0 rank -127: htable [main] 0(10321) DEBUG: htable [htable.c:232]: child_init(): rank is (-127) 0(10321) DEBUG: htable [htable.c:265]: child_init(): executing event_route[htable:mod-init] (-1) 0(10321) DEBUG: <core> [core/parser/msg_parser.c:604]: parse_msg(): SIP Request: 0(10321) DEBUG: <core> [core/parser/msg_parser.c:606]: parse_msg(): method: <OPTIONS> 0(10321) DEBUG: <core> [core/parser/msg_parser.c:608]: parse_msg(): uri: sip:you@kamailio.org 0(10321) DEBUG: <core> [core/parser/msg_parser.c:610]: parse_msg(): version: <SIP/2.0> 0(10321) DEBUG: <core> [core/parser/parse_via.c:2639]: parse_via(): end of header reached, state=2 0(10321) DEBUG: <core> [core/parser/msg_parser.c:492]: parse_headers(): Via found, flags=2 0(10321) DEBUG: <core> [core/parser/msg_parser.c:494]: parse_headers(): this is the first via 0(10321) ERROR: app_lua [app_lua_api.c:652]: app_lua_run_ex(): lua loading state not initialized (call: ksr_htable_event) 0(10321) DEBUG: app_lua [app_lua_mod.c:161]: sr_kemi_config_engine_lua(): execution of route type 513 with name [ksr_htable_event] returned -1
It needs investigation in the code, the callback is executed before app_lua initialises the kemi engine, a solution needs to be done for it.
I pushed a commit referenced above. Can you test with master and set the event_callback_mode parameter to 1 for htable module?
yes i will test now
First of all Thanks for resolving this issue. I have following findings:: 1. event_callback_mode type is str, i raised to pull request to change this to str (#1522) 2. htable:mod-init event is called 8 times (8 children) but again it should be called only once as htable is shared memory. when i changed the str to int, its calling only once, i think that is perfect.
I understand that with your pull request (which I just merged) all is fine. I am going to close this one and backport to 5.1.
Closed #1519.
@miconda please backport to 5.1. i will test again with 5.1
Done.