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.