Hi All,
I'm using app_python with a KEMI Python routing script. I have been getting occasional Python exception error logs :
kamailio[2242]: 8(2253) ERROR: app_python [python_support.c:150]: python_handle_exception(): python_exec2: Unhandled exception in the Python code: kamailio[2242]: TypeError: an integer is required
The scripts seems to function without an issue but these error logs appear fairly frequently, always with an empty Python stack trace.
I am running Kamailio 5.1 on a Debian 9 system and using Python 2.7 :
:/usr/local/etc/kamailio# python --version
Python 2.7.13
:/usr/local/etc/kamailio# kamailio -v
version: kamailio 5.1.4 (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 18:56:43 Jun 8 2018 with gcc 6.3.0
I have also tried using a Kamailio load built from the master branch (commit f8b8cecb) which gives enhanced exception logging identifying the function an exception occurs within and parameters. I see this occurring in different parts of the routing script e.g.
from script
def ksr_onsend_route(self,msg): KSR.xlog.xdbg("ONSEND_ROUTE fs=[$fs] $mb\n"); return 1;
an exception is reported within ksr_onsend_route() even when the log level is info.
Changing log to xlog.xinfo, the log is seen to be sent to syslog but again the exception is reported. These exceptions are always "TypeError: an integer is required" but don't seem related to the Python script.
Here is an example of the log with a patch applied to to Kamailio 5.1 to show the function the exception is reported within.
kamailio[14092]: 6(14103) ERROR: app_python [python_support.c:156]: python_handle_exception(): apy_exec: ksr_reply_route((null)): Unhandled exception in the Python code: kamailio[14092]: TypeError: an integer is required . . . kamailio[14092]: 22(14119) INFO: <script>: ONSEND_ROUTE fs=[udp: 10.0.31.126:5080] ACK sip:10008@media.test.io:5061;transport=TLS SIP/2.0 . . . . kamailio[14092]: 22(14119) ERROR: app_python [python_support.c:156]: python_handle_exception(): apy_exec: ksr_onsend_route((null)): Unhandled exception in the Python code: kamailio[14092]: TypeError: an integer is required
Has anyone got an idea what can be causing these exceptions and how to avoid them? Currently I have simply patched the load to drop the level of this log to debug when such an exception occurs with an empty traceback as they seem spurious.
Cheers Mike
On Mon, Jun 18, 2018 at 12:05:34PM -0400, Michael Loughrey wrote:
kamailio[2242]: 8(2253) ERROR: app_python [python_support.c:150]: python_handle_exception(): python_exec2: Unhandled exception in the Python code: kamailio[2242]: TypeError: an integer is required
Hi Michael,
This is usually a symptom of a ksr_* method having a code path which exits the function without returning an integer value (1 for success, 0 for immediate exit, and < 0 for failure) — the equivalent of a None return value. That might be the cause of the TypeError.
Can you ensure that all your ksr_* methods have an integer return value no matter how they return.
If this doesn't work, are you able to share your routing script?
Regards
Anthony
Thanks for the tip Anthony. I do indeed have a couple of ksr_ routines returning no value.
From kamailio.cfg
####### Routing Logic ########
modparam("xhttp", "event_callback", "ksr_xhttp_event") modparam("htable", "event_callback_mode", 1) modparam("htable", "event_callback", "ksr_htable_event") modparam("dialog", "event_callback", "ksr_dialog_event") modparam("app_python", "load", "/usr/local/etc/kamailio/routing.py") cfgengine "python"
In routing.py
ksr_dialog_event(self,msg,evname)
ksr_htable_event(self,msg,evname)
are not returning values. I will correct these to always return 1. Hopefully that resolves the issue. Could you confirm that a return value of 0 from routes such as those set in
KSR.tm.t_on_failure
is the equivalent to exit & drop.
Cheers
Mike
ksr_dialog_event
On Mon, 18 Jun 2018 at 20:10, Anthony Alba ascanio.alba7@gmail.com wrote:
On Mon, Jun 18, 2018 at 12:05:34PM -0400, Michael Loughrey wrote:
kamailio[2242]: 8(2253) ERROR: app_python [python_support.c:150]: python_handle_exception(): python_exec2: Unhandled exception in the
Python
code: kamailio[2242]: TypeError: an integer is required
Hi Michael,
This is usually a symptom of a ksr_* method having a code path which exits the function without returning an integer value (1 for success, 0 for immediate exit, and < 0 for failure) — the equivalent of a None return value. That might be the cause of the TypeError.
Can you ensure that all your ksr_* methods have an integer return value no matter how they return.
If this doesn't work, are you able to share your routing script?
Regards
Anthony
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
I confirmed that the issue was the missing return values for ksr_dialog_event() and ksr_htable_event(). Once added the exception errors no longer occur. Thanks for the help.
Cheers Mike
On Mon, 18 Jun 2018 at 21:26, Michael Loughrey mgloughrey@gmail.com wrote:
Thanks for the tip Anthony. I do indeed have a couple of ksr_ routines returning no value.
From kamailio.cfg
####### Routing Logic ########
modparam("xhttp", "event_callback", "ksr_xhttp_event") modparam("htable", "event_callback_mode", 1) modparam("htable", "event_callback", "ksr_htable_event") modparam("dialog", "event_callback", "ksr_dialog_event") modparam("app_python", "load", "/usr/local/etc/kamailio/routing.py") cfgengine "python"
In routing.py
ksr_dialog_event(self,msg,evname)
ksr_htable_event(self,msg,evname)
are not returning values. I will correct these to always return 1. Hopefully that resolves the issue. Could you confirm that a return value of 0 from routes such as those set in
KSR.tm.t_on_failure
is the equivalent to exit & drop.
Cheers
Mike
ksr_dialog_event
On Mon, 18 Jun 2018 at 20:10, Anthony Alba ascanio.alba7@gmail.com wrote:
On Mon, Jun 18, 2018 at 12:05:34PM -0400, Michael Loughrey wrote:
kamailio[2242]: 8(2253) ERROR: app_python [python_support.c:150]: python_handle_exception(): python_exec2: Unhandled exception in the
Python
code: kamailio[2242]: TypeError: an integer is required
Hi Michael,
This is usually a symptom of a ksr_* method having a code path which exits the function without returning an integer value (1 for success, 0 for immediate exit, and < 0 for failure) — the equivalent of a None return value. That might be the cause of the TypeError.
Can you ensure that all your ksr_* methods have an integer return value no matter how they return.
If this doesn't work, are you able to share your routing script?
Regards
Anthony
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users