Re: Catching 'out of memory' using pcall()

  • From: Dmitri Shubin <sbn@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 13 Mar 2014 12:27:49 +0400

On 03/13/2014 11:12 AM, Coda Highland wrote:
On Thu, Mar 13, 2014 at 12:06 AM, Dmitri Shubin <sbn@xxxxxxxxxxx> wrote:
Is it possible to catch 'out of memory' condition using pcall() ?
Does your error handler need to allocate memory?

Well, the main problem we have is that our application (that uses luajit for scripting) is crashed when reaching known limit of 1GiB for lua states on Linux/x86_64. So we want to be able to catch this condition and simply abort script execution.

Now the crash has the following stack trace:

#0 tbricks::transport::CRASH_HANDLER (signum=11) at src/Application.cpp:1005
#1  <signal handler called>
#2 0x00007fb10287ffac in err_unwind (L=0x7bbf9378, stopcf=0x7fb0e97f9500, errcode=0) at lj_err.c:113 #3 0x00007fb10287fbb7 in lj_err_unwind_dwarf (version=1, actions=1, uexclass=5500374307216568836, uex=0x7fb0e97fc5e0, ctx=0x7fb0e97f90c0) at lj_err.c:247 #4 0x00007fb0ff864686 in _Unwind_RaiseException () from /lib64/libgcc_s.so.1
#5  0x00007fb10288049a in err_raise_ext (errcode=4) at lj_err.c:308
#6 0x00007fb102880400 in lj_err_throw (L=0x7bbf9378, errcode=4) at lj_err.c:462
#7  0x00007fb1028805f4 in lj_err_mem (L=0x7bbf9378) at lj_err.c:498
#8 0x00007fb10287d831 in lj_mem_newgco (L=0x7bbf9378, size=32) at lj_gc.c:818 #9 0x00007fb102883cb8 in newtab (L=0x7bbf9378, asize=0, hbits=1) at lj_tab.c:112 #10 0x00007fb10288404a in lj_tab_dup (L=0x7bbf9378, kt=0x7bc10cb8) at lj_tab.c:167 #11 0x00007fb10287847a in lj_BC_TDUP () from /home/sbn/tb/tb/build.x86_64-unknown-linux/bin/../platform/lib64/libluajit-5.1.so.2 #12 0x00007fb10289c195 in lua_pcall (L=0x7bbf9378, nargs=2, nresults=0, errfunc=0) at lj_api.c:1055
<application-specific frames omitted>

Other related posts: