2

We have created a multithreaded, single core application running on Ubuntu.

When we call getaddrinfo and gethostbyname from the main process, it does not crash.

However when we create a thread from the main process and the functions getaddrinfo and gethostbyname are called from the created thread, it always crashes.

Kindly help. Please find the call stack below:

#0  0xf7e9f890 in ?? () from /lib/i386-linux-gnu/libc.so.6
#1  0xf7e9fa73 in __res_ninit () from /lib/i386-linux-gnu/libc.so.6
#2  0xf7ea0a68 in __res_maybe_init () from /lib/i386-linux-gnu/libc.so.6
#3  0xf7e663be in ?? () from /lib/i386-linux-gnu/libc.so.6
#4  0xf7e696bb in getaddrinfo () from /lib/i386-linux-gnu/libc.so.6
#5  0x080c4e35 in mn_task_entry (args=0xa6c4130 <ipc_os_input_params>) at /home/nextg/Alps_RT/mn/src/mn_main.c:699
#6  0xf7fa5d78 in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#7  0xf7e9001e in clone () from /lib/i386-linux-gnu/libc.so.6
Syed Aslam
  • 79
  • 7
  • 1
    You haven't shown any code. Time to learn how to use gdb. – vanza Sep 26 '14 at 17:06
  • `gethostbyname` is not required to be reentrant and as such is probably not thread safe if called from multiple threads. If you are using `glibc` as your c library, you can try using `gethostbyname_r` to see if that solves the problem. – John Ledbetter Sep 26 '14 at 17:26

2 Answers2

3

The reason the getaddrinfo was crashing because, the child thread making the call did not have sufficient stack space.

Syed Aslam
  • 79
  • 7
0

Using ACE C++ version 6.5.1 libraries classes which use ACE_Thread::spawn_n with default ACE_DEFAULT_THREAD_PRIORITY (1024*1024) will crash when calling gethostbyname/getaddrinfo inside child as reported by Syed Aslam. libxml2 schema parsing takes forever, using a child thread Segment Faulted after calling xmlNanoHTTPConnectHost as it tries to resolve schemaLocation.

ACE_Task activate

const ACE_TCHAR *thr_name[1];
thr_name[0] = "Flerf";
// libxml2-2.9.7/nanohttp.c:1133
// gethostbyname will crash when child thread making the call 
// has insufficient stack space.
size_t stack_sizes[1] = {
  ACE_DEFAULT_THREAD_STACKSIZE * 100
};

const INT ret = this->activate (
  THR_NEW_LWP/*Light Weight Process*/ | THR_JOINABLE,
  1,
  0/*force_active*/,
  ACE_DEFAULT_THREAD_PRIORITY,
  -1/*grp_id*/,
  NULL/*task*/,
  NULL/*thread_handles[]*/,
  NULL/*stack[]*/,
  stack_sizes/*stack_size[]*/,
  NULL/*thread_ids[]*/,
  thr_name
);
Ako
  • 956
  • 1
  • 10
  • 13