Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app_ruby: print backtrace when ruby exception occurs #1766

Closed
fatihorhan opened this issue Dec 14, 2018 · 2 comments
Closed

app_ruby: print backtrace when ruby exception occurs #1766

fatihorhan opened this issue Dec 14, 2018 · 2 comments

Comments

@fatihorhan
Copy link

Description

Hello,

When there is an error in my ruby script, app_ruby prints exception message without a stack trace, like this:

Dec 14 16:25:17 servername /usr/sbin/kamailio[24313]: ERROR: app_ruby [app_ruby_api.c:105]: app_ruby_print_last_exception(): exception: wrong number of arguments (1 for 2..3)
Dec 14 16:25:17 servername /usr/sbin/kamailio[24313]: ERROR: app_ruby [app_ruby_api.c:1078]: app_ruby_run_ex(): ruby exception (6) on callback for: ksr_request_route (res type: 17)

Altough this message tells what is the error, it doesn't tell where the error happened, so it's hard to find the source of the problem.

In ruby, exceptions have backtrace() method returning stack trace as an array of strings. It would be really helpful if app_ruby also call this method and append its result to error message.

Reproduction

in kamailio.cfg

loadmodule "app_ruby.so"
modparam("app_ruby", "load", "/etc/kamailio/ruby/routes.rb")
cfgengine "ruby"

in /etc/kamailio/ruby/routes.rb

def some_method(param1, param2)
end

def ksr_request_route
  some_method(1)
end

Expected behavior

Dec 14 16:46:24 servername /usr/sbin/kamailio[24314]: ERROR: <core> [core/kemi.c:87]: sr_kemi_core_err(): wrong number of arguments (1 for 2): /etc/kamailio/ruby/routes.rb:1:in `some_method'
                                                                     /etc/kamailio/ruby/routes.rb:4:in `ksr_request_route'

Actual observed behavior

Dec 14 16:45:42 servername /usr/sbin/kamailio[24311]: ERROR: app_ruby [app_ruby_api.c:105]: app_ruby_print_last_exception(): exception: wrong number of arguments (1 for 2)

Possible Solutions

Relevant code seem to be here: https://github.com/kamailio/kamailio/blob/master/src/modules/app_ruby/app_ruby_api.c#L98

I found example C code to print stack trace here but couldn't figure out how to integrate to app_ruby: http://zoo-project.org/svn/trunk/zoo-project/zoo-kernel/service_internal_ruby.c

Equivalent ruby code would be (this code is not idiomatic, my aim is to provide C-like ruby code):

def some_error_generating_method
  method_taking_two_params(1)
rescue => exception
  message = exception.to_s() + "\n"
  stack_trace = exception.backtrace()
  for line in stack_trace
    message = message + line + "\n"
  end
  print(message)
end

Additional Information

  • Kamailio Version - output of kamailio -v
version: kamailio 5.2.0 (x86_64/linux) 535e13
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, 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_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: 535e13
compiled on 10:26:34 Nov 28 2018 with gcc 4.8.5
  • Operating System:

Centos 7.2 64bit

Linux servername 3.10.0-327.28.2.el7.x86_64 #1 SMP Wed Aug 3 11:11:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

@miconda
Copy link
Member

miconda commented Dec 17, 2018

If someone can propose a pull request for this feature, I will happily merge it. Right now, I am not sure when I will get some time to look deeper at it.

Copy link

github-actions bot commented Nov 8, 2023

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.

@github-actions github-actions bot added the Stale label Nov 8, 2023
@fatihorhan fatihorhan closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants