Skip to end of metadata
Go to start of metadata

Context

I've been chasing a strange nondeterministic stack corruption lately in our fresh FreeSwitch + FreeTDM install.
Every now and then FreeSwitch dumped core that had apparent stack corruption that was untraceable most of the time.
I've managed to narrow it down to one of our Lua scripts - a call to socket.tcp:connect to be exact.

This was happening 60% of time when running FreeSwitch+FreeTDM (SS7 on 8E1s).
Never on FreeSwitch alone (with less < 500 SIP calls).
Never when running under GDB (even with FreeTDM SS7 stuff) (sad)

Facts

  1. Luasocket defaults to using select system call when operating on sockets.
  2. Luasocket uses unsafe FD_SET macros to operate on local fd_set structure.
  3. FreeTDM uses > 1024 file descriptors for 8E1s worth of TDM channels

Solution

Make luasocket use poll instead of select
Add -DSOCKET_POLL to DEF line in luasocket config file before compiling the whole thing