Hello, I'm using radiusclient lib from multithreaded application, by having a "static rc_handle *rh" and calling rc_auth() from different threads. Everything works until 2 (or more) threads enter rc_auth() before the previous one finished. But 2 concurrent threads enough to corrupt everything, I'm starting to get "received invalid reply digest..." followed by "no reply from RADIUS server" for subsequent calls. I changed rc_check_reply() to return OK at the beginning, it eliminated "received invalid reply", but I still get "no reply from RADIUS server ...". In wireshark trace it looks like there's no problems with responses, every request receives response (and before timeout should happen). It looks like something logical, shared or static buffer maybe. I'm looking in the code and can't find the problem :( I changed localtime to localtime_r, gmtime to gmtime_r, rand to rand_r, but still have a problem. In the trace: ->request <-response ->request <-response Works well, but looks like enough to have: ->request ->request <-response <-response To cause most of (not every) following subsequent request to get "no reply..." although there're responses in the trace. Also my distro has old radiusclient-ng and not freeradiusclient, but as far as I understood there's no difference in this section. Can someone enlighten me on the subj please? -- BR, Alex. This mail was sent via Mail-SeCure System.
Alex Massover wrote:
Hello,
I'm using radiusclient lib from multithreaded application, by having a "static rc_handle *rh" and calling rc_auth() from different threads.
It's not thread-safe. There are no mutex locks in the code.
Can someone enlighten me on the subj please?
Use one rc_handle per child thread. The code needs pretty significant changes to make it thread-safe. Alan DeKok.
Hi Alan, Thank you for reply. I tested it now with rc_handle per thread but the problem still persists. Even if I protect all calls to libradius with mutex: pthread_mutex_lock(&mp); rc_init_handle(); [build send avpair here] rc_auth(); rc_free_handle(); pthread_mutex_unlock(&mp); Looks like memory corruption, because if I don't leave thread to leave for a long time, the problem disappears. Probably if thread exits it cleans up stack (or maybe because this way there're no 2 concurrent threads that ran through rc_auth() ). So I compiled it with -fstack-protector-all, but it didn't fixed the problem. Here's what I did, in lib/sendserver.c in rc_send_server() I added break, to disable exiting with TIMEOUT_RC, like following: if (FD_ISSET (sockfd, &readfds)) break; /* * Timed out waiting for response. Retry "retry_max" times * before giving up. If retry_max = 0, don't retry at all. */ if (++retries >= retry_max) { break; // ########################################## HERE ####################### rc_log(LOG_ERR, "rc_send_server: no reply from RADIUS server"); close (sockfd); memset (secret, '\0', sizeof (secret)); return TIMEOUT_RC; } And magically it fixed the issue. That's beyond of my understanding, but looks like if (FD_ISSET (sockfd, &readfds)) break; misbehaves (or gets corrupted). Only rare I get "rc_send_server: select: Bad file descriptor". What do you think please?
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום ו 26 פברואר 2010 17:51 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Hello,
I'm using radiusclient lib from multithreaded application, by having a "static rc_handle *rh" and calling rc_auth() from different threads.
It's not thread-safe. There are no mutex locks in the code.
Can someone enlighten me on the subj please?
Use one rc_handle per child thread.
The code needs pretty significant changes to make it thread-safe.
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
Alex Massover wrote:
Here's what I did, in lib/sendserver.c in rc_send_server() I added break, to disable exiting with TIMEOUT_RC, like following:
if (FD_ISSET (sockfd, &readfds)) break;
What code are you looking at? That code isn't in current CVS for freeradius-client. Alan DeKok.
Hi, I use radiusclient-ng code base, but freeradiusclient has exactly the same code, at least the latest release downloaded from here: ftp://ftp.freeradius.org/pub/freeradius/freeradius-client-1.1.6.tar.bz2 It's in lib/sendserver.c line 322 (there's only one FD_ISSET)
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום א 28 פברואר 2010 13:08 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Here's what I did, in lib/sendserver.c in rc_send_server() I added break, to disable exiting with TIMEOUT_RC, like following:
if (FD_ISSET (sockfd, &readfds)) break;
What code are you looking at? That code isn't in current CVS for freeradius-client.
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
Alex Massover wrote:
Hi,
I use radiusclient-ng code base, but freeradiusclient has exactly the same code, at least the latest release downloaded from here:
ftp://ftp.freeradius.org/pub/freeradius/freeradius-client-1.1.6.tar.bz2
It's in lib/sendserver.c line 322 (there's only one FD_ISSET)
OK. Then try grabbing the latest version from CVS. It has a number of fixes. http://freeradius.org/development.html#cvs Alan DeKok.
Hi, Here's what I get with latest code from CVS: Program terminated with signal 11, Segmentation fault. #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 #1 0xb61540f0 in rc_send_server () from /usr/lib/libfreeradius-client.so.2 #2 0xb6152c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #3 0xb6152ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #4 0xb616c52f in sendrad_exec_generic (chan=0x9477088, data=<value optimized out>, type=0) at app_sendradevent.c:212 #5 0x080f67c7 in pbx_exec () #6 0x080f76d0 in ?? () #7 0x080f933f in ?? () #8 0x080fa5f0 in ?? () #9 0x081346fb in ?? () #10 0xb7468585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #11 0xb768b27e in clone () from /lib/i686/cmov/libc.so.6 (gdb) quit And the strange thing is that sometimes (rarely) it works, exactly the same code. Compiled with CFLAGS="-pthread -D_REENTRANT -fstack-protector-all" Or #0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 #1 0xb601a417 in rc_find_server () from /usr/lib/libfreeradius-client.so.2 #2 0xb6016119 in rc_send_server () from /usr/lib/libfreeradius-client.so.2 #3 0xb6014c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #4 0xb6014ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #5 0xb602e52f in sendrad_exec_generic (chan=0x8a96e70, data=<value optimized out>, type=0) at app_sendradevent.c:212 #6 0x080f67c7 in pbx_exec () #7 0x080f76d0 in ?? () #8 0x080f933f in ?? () #9 0x080fa5f0 in ?? () #10 0x081346fb in ?? () #11 0xb742a585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #12 0xb764d27e in clone () from /lib/i686/cmov/libc.so.6
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום א 28 פברואר 2010 13:56 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Hi,
I use radiusclient-ng code base, but freeradiusclient has exactly the same code, at least the latest release downloaded from here:
ftp://ftp.freeradius.org/pub/freeradius/freeradius-client- 1.1.6.tar.bz2
It's in lib/sendserver.c line 322 (there's only one FD_ISSET)
OK. Then try grabbing the latest version from CVS. It has a number of fixes.
http://freeradius.org/development.html#cvs
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
Sorry, please ignore, I overwrote configs by mistake.
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 13:51 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Hi,
Here's what I get with latest code from CVS:
Program terminated with signal 11, Segmentation fault. #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 #1 0xb61540f0 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6152c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #3 0xb6152ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #4 0xb616c52f in sendrad_exec_generic (chan=0x9477088, data=<value optimized out>, type=0) at app_sendradevent.c:212 #5 0x080f67c7 in pbx_exec () #6 0x080f76d0 in ?? () #7 0x080f933f in ?? () #8 0x080fa5f0 in ?? () #9 0x081346fb in ?? () #10 0xb7468585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #11 0xb768b27e in clone () from /lib/i686/cmov/libc.so.6 (gdb) quit
And the strange thing is that sometimes (rarely) it works, exactly the same code.
Compiled with CFLAGS="-pthread -D_REENTRANT -fstack-protector-all"
Or
#0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 #1 0xb601a417 in rc_find_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6016119 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #3 0xb6014c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #4 0xb6014ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #5 0xb602e52f in sendrad_exec_generic (chan=0x8a96e70, data=<value optimized out>, type=0) at app_sendradevent.c:212 #6 0x080f67c7 in pbx_exec () #7 0x080f76d0 in ?? () #8 0x080f933f in ?? () #9 0x080fa5f0 in ?? () #10 0x081346fb in ?? () #11 0xb742a585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #12 0xb764d27e in clone () from /lib/i686/cmov/libc.so.6
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום א 28 פברואר 2010 13:56 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Hi,
I use radiusclient-ng code base, but freeradiusclient has exactly the same code, at least the latest release downloaded from here:
ftp://ftp.freeradius.org/pub/freeradius/freeradius-client- 1.1.6.tar.bz2
It's in lib/sendserver.c line 322 (there's only one FD_ISSET)
OK. Then try grabbing the latest version from CVS. It has a number of fixes.
http://freeradius.org/development.html#cvs
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
Hmmm.. Sorry again. This is not result of wrong configs. This is what I get when I do rc_handle per thread: rc_handle *rh; if ((rh = rc_read_config(RC_CONFIG_FILE)) == NULL) { ... } if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {...} [...build send avpair...] rc_auth(); If I have a static rc_handle and call rc_read_config() and rc_read_dictionary() in parent there's no such problem. I'm even able to call rc_avpiar_log() just before rc_auth() and get correct dump of my avpiar.
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 14:01 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Sorry, please ignore, I overwrote configs by mistake.
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 13:51 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Hi,
Here's what I get with latest code from CVS:
Program terminated with signal 11, Segmentation fault. #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 #1 0xb61540f0 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6152c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #3 0xb6152ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #4 0xb616c52f in sendrad_exec_generic (chan=0x9477088, data=<value optimized out>, type=0) at app_sendradevent.c:212 #5 0x080f67c7 in pbx_exec () #6 0x080f76d0 in ?? () #7 0x080f933f in ?? () #8 0x080fa5f0 in ?? () #9 0x081346fb in ?? () #10 0xb7468585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #11 0xb768b27e in clone () from /lib/i686/cmov/libc.so.6 (gdb) quit
And the strange thing is that sometimes (rarely) it works, exactly the same code.
Compiled with CFLAGS="-pthread -D_REENTRANT -fstack-protector-all"
Or
#0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 #1 0xb601a417 in rc_find_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6016119 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #3 0xb6014c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #4 0xb6014ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #5 0xb602e52f in sendrad_exec_generic (chan=0x8a96e70, data=<value optimized out>, type=0) at app_sendradevent.c:212 #6 0x080f67c7 in pbx_exec () #7 0x080f76d0 in ?? () #8 0x080f933f in ?? () #9 0x080fa5f0 in ?? () #10 0x081346fb in ?? () #11 0xb742a585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #12 0xb764d27e in clone () from /lib/i686/cmov/libc.so.6
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel- bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום א 28 פברואר 2010 13:56 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Hi,
I use radiusclient-ng code base, but freeradiusclient has exactly the same code, at least the latest release downloaded from here:
ftp://ftp.freeradius.org/pub/freeradius/freeradius-client- 1.1.6.tar.bz2
It's in lib/sendserver.c line 322 (there's only one FD_ISSET)
OK. Then try grabbing the latest version from CVS. It has a number of fixes.
http://freeradius.org/development.html#cvs
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
BTW, looks like there're no seqfaults/strange behavior anymore with static rc_handle with version from CVS. I have only very early results now, will continue to test it. -----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 15:37 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety Hmmm.. Sorry again. This is not result of wrong configs. This is what I get when I do rc_handle per thread: rc_handle *rh; if ((rh = rc_read_config(RC_CONFIG_FILE)) == NULL) { ... } if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {...} [...build send avpair...] rc_auth(); If I have a static rc_handle and call rc_read_config() and rc_read_dictionary() in parent there's no such problem. I'm even able to call rc_avpiar_log() just before rc_auth() and get correct dump of my avpiar.
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 14:01 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Sorry, please ignore, I overwrote configs by mistake.
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 13:51 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Hi,
Here's what I get with latest code from CVS:
Program terminated with signal 11, Segmentation fault. #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 #1 0xb61540f0 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6152c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #3 0xb6152ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #4 0xb616c52f in sendrad_exec_generic (chan=0x9477088, data=<value optimized out>, type=0) at app_sendradevent.c:212 #5 0x080f67c7 in pbx_exec () #6 0x080f76d0 in ?? () #7 0x080f933f in ?? () #8 0x080fa5f0 in ?? () #9 0x081346fb in ?? () #10 0xb7468585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #11 0xb768b27e in clone () from /lib/i686/cmov/libc.so.6 (gdb) quit
And the strange thing is that sometimes (rarely) it works, exactly the same code.
Compiled with CFLAGS="-pthread -D_REENTRANT -fstack-protector-all"
Or
#0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 #1 0xb601a417 in rc_find_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6016119 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #3 0xb6014c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #4 0xb6014ec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #5 0xb602e52f in sendrad_exec_generic (chan=0x8a96e70, data=<value optimized out>, type=0) at app_sendradevent.c:212 #6 0x080f67c7 in pbx_exec () #7 0x080f76d0 in ?? () #8 0x080f933f in ?? () #9 0x080fa5f0 in ?? () #10 0x081346fb in ?? () #11 0xb742a585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #12 0xb764d27e in clone () from /lib/i686/cmov/libc.so.6
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel- bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום א 28 פברואר 2010 13:56 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Hi,
I use radiusclient-ng code base, but freeradiusclient has exactly the same code, at least the latest release downloaded from here:
ftp://ftp.freeradius.org/pub/freeradius/freeradius-client- 1.1.6.tar.bz2
It's in lib/sendserver.c line 322 (there's only one FD_ISSET)
OK. Then try grabbing the latest version from CVS. It has a number of fixes.
http://freeradius.org/development.html#cvs
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System. This mail was sent via Mail-SeCure System.
Hi, Here're more updated results: a) with rc_handle per thread it segfaults on the first call to rc_auth(). Please see below. b) with static rc_handle it works for single calls but fails on heavy multithreading: #0 0xb6122b42 in rc_get_ipaddr () from /usr/lib/libfreeradius-client.so.2 (gdb) bt #0 0xb6122b42 in rc_get_ipaddr () from /usr/lib/libfreeradius-client.so.2 #1 0xb61211dc in rc_find_server () from /usr/lib/libfreeradius-client.so.2 #2 0xb611d119 in rc_send_server () from /usr/lib/libfreeradius-client.so.2 #3 0xb611bc32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #4 0xb611bec4 in rc_auth () from /usr/lib/libfreeradius-client.so.2 #5 0xb61354ea in sendrad_exec_generic (chan=0xa896d0a0, data=<value optimized out>, type=0) at app_sendradevent.c:214 #6 0x080f67c7 in pbx_exec () #7 0x080f76d0 in ?? () #8 0x080f933f in ?? () #9 0x080fa5f0 in ?? () #10 0x081346fb in ?? () #11 0xb73f6585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #12 0xb761927e in clone () from /lib/i686/cmov/libc.so.6 Also regardless of rc_handle the lib has a lot of non-reentrant functions (inet_ntoa, localtime, gmtime, random, rand...). Does it supposed to be thread-safe even if there's no logical issue with rc_handle?
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 15:37 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Hmmm.. Sorry again. This is not result of wrong configs. This is what I get when I do rc_handle per thread:
rc_handle *rh; if ((rh = rc_read_config(RC_CONFIG_FILE)) == NULL) { ... } if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {...} [...build send avpair...] rc_auth();
If I have a static rc_handle and call rc_read_config() and rc_read_dictionary() in parent there's no such problem.
I'm even able to call rc_avpiar_log() just before rc_auth() and get correct dump of my avpiar.
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 14:01 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Sorry, please ignore, I overwrote configs by mistake.
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel- bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alex Massover Sent: יום ב 01 מרץ 2010 13:51 To: FreeRadius developers mailing list Subject: RE: radiusclient thread-safety
Hi,
Here's what I get with latest code from CVS:
Program terminated with signal 11, Segmentation fault. #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb762fd19 in strncpy () from /lib/i686/cmov/libc.so.6 #1 0xb61540f0 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6152c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #3 0xb6152ec4 in rc_auth () from /usr/lib/libfreeradius- client.so.2 #4 0xb616c52f in sendrad_exec_generic (chan=0x9477088, data=<value optimized out>, type=0) at app_sendradevent.c:212 #5 0x080f67c7 in pbx_exec () #6 0x080f76d0 in ?? () #7 0x080f933f in ?? () #8 0x080fa5f0 in ?? () #9 0x081346fb in ?? () #10 0xb7468585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #11 0xb768b27e in clone () from /lib/i686/cmov/libc.so.6 (gdb) quit
And the strange thing is that sometimes (rarely) it works, exactly the same code.
Compiled with CFLAGS="-pthread -D_REENTRANT -fstack-protector-all"
Or
#0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 (gdb) bt #0 0xb75f19cb in strlen () from /lib/i686/cmov/libc.so.6 #1 0xb601a417 in rc_find_server () from /usr/lib/libfreeradius- client.so.2 #2 0xb6016119 in rc_send_server () from /usr/lib/libfreeradius- client.so.2 #3 0xb6014c32 in rc_aaa () from /usr/lib/libfreeradius-client.so.2 #4 0xb6014ec4 in rc_auth () from /usr/lib/libfreeradius- client.so.2 #5 0xb602e52f in sendrad_exec_generic (chan=0x8a96e70, data=<value optimized out>, type=0) at app_sendradevent.c:212 #6 0x080f67c7 in pbx_exec () #7 0x080f76d0 in ?? () #8 0x080f933f in ?? () #9 0x080fa5f0 in ?? () #10 0x081346fb in ?? () #11 0xb742a585 in start_thread () from /lib/i686/cmov/libpthread.so.0 #12 0xb764d27e in clone () from /lib/i686/cmov/libc.so.6
-----Original Message----- From: freeradius-devel- bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel- bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום א 28 פברואר 2010 13:56 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Hi,
I use radiusclient-ng code base, but freeradiusclient has exactly the same code, at least the latest release downloaded from here:
ftp://ftp.freeradius.org/pub/freeradius/freeradius-client- 1.1.6.tar.bz2
It's in lib/sendserver.c line 322 (there's only one FD_ISSET)
OK. Then try grabbing the latest version from CVS. It has a number of fixes.
http://freeradius.org/development.html#cvs
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
Alex Massover wrote:
Also regardless of rc_handle the lib has a lot of non-reentrant functions (inet_ntoa, localtime, gmtime, random, rand...). Does it supposed to be thread-safe even if there's no logical issue with rc_handle?
Probably not. For a thread-safe RADIUS client library (LGPL), see freeradius-server, src/lib. See src/main/radclient.c for an example client. The client doesn't use threads. But the functions in src/lib are thread-safe if they're protected by a mutex lock. Alan DeKok.
Hi, Here's a small non-reentrant clean-up patch: a) localtime(), gmtime(), getserbyname(), rand() switch to _r interfaces b) inet_ntoa -> inet_ntop c) poll() expect timeout in milliseconds, not in microseconds d) request id is now just pre-increment - faster and simplier than random
-----Original Message----- From: freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org [mailto:freeradius-devel-bounces+alex=jajah.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: יום ג 02 מרץ 2010 10:23 To: FreeRadius developers mailing list Subject: Re: radiusclient thread-safety
Alex Massover wrote:
Also regardless of rc_handle the lib has a lot of non-reentrant functions (inet_ntoa, localtime, gmtime, random, rand...). Does it supposed to be thread-safe even if there's no logical issue with rc_handle?
Probably not.
For a thread-safe RADIUS client library (LGPL), see freeradius- server, src/lib. See src/main/radclient.c for an example client.
The client doesn't use threads. But the functions in src/lib are thread-safe if they're protected by a mutex lock.
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
This mail was received via Mail-SeCure System.
This mail was sent via Mail-SeCure System.
participants (2)
-
Alan DeKok -
Alex Massover