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) ![]()
Facts
- Luasocket defaults to using
selectsystem call when operating on sockets. - Luasocket uses unsafe
FD_SETmacros to operate on localfd_setstructure. - 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