[Libevent-users] Simple question about multithreading SSL bufferevents.
Hello all, I am having significant issues with (near immediate) deadlock when trying to send data out a single openssl bufferevent from two separate threads. The individual threads themselves send complete messages with each write. This should present no real problem from a synchronization perspective. In fact, the code works flawlessly when using ordinary bufferevents (not ssl bufferevents). Are there any known issues with writing to a single openssl bufferevent from multiple threads concurrently? Should I have the expectation of this working, presuming my code is written correctly? I believe I have initialized libevent and openssl correctly for multithreaded execution. Thanks, -John More info, for those interested: My code fails in the same manner on both OSX and Linux. Both are built with multithreaded libevent/openssl support. (Verified at build time, not programatically. What's a good way to test openssl itself to see if it was built thread safe? I have verified openssl is calling my locking routines with a variety of lock indexes and the like) I am running: SSL version: OpenSSL 1.0.1c 10 May 2012 Libevent version: 2.0.21-stable I have done the following: 1. Initialized openssl per Viega/Messier/Chandra, "Network Security with OpenSSL". (Before using any SSL.) 2. Initialized libevent with evthread_use_pthreads() (Before using any libevent- and verified result) 3. Use option BEV_OPT_THREADSAFE on the bufferevents being created. And the following, none of which should be required, and none of which helped: 1. Used a global mutex surrounding all calls to libevent. 2. called evbuffer_enable_locking() on both evbuffers associated with the bufferevent. And verified, for sanity: 1. The shared libraries I am loading are the libraries I expect the system to use. My server is simply openssl acting as server, using some simple genetated certificates. I would be happy to share my test code- but it is ~300ish lines due to (primarily) openssl and thread initialization. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
Re: [Libevent-users] Simple question about multithreading SSL bufferevents.
Mark, Yes, I have enabled OpenSSL locking, including setting up dynamic locking. I have verified the locks are "running" by watching the various lock callbacks occuring. I "stole" the locking code from the book "Network Security with OpenSSL", by Viega/Messier/Chandra. Thanks, -John - Original Message - From: Mark Ellzey To: libevent-us...@freehaven.net Cc: Sent: Wednesday, March 27, 2013 7:23 AM Subject: Re: [Libevent-users] Simple question about multithreading SSL bufferevents. On Tue, Mar 26, 2013 at 03:32:17PM -0700, John wrote: > Hello all, > > I am having significant issues with (near immediate) deadlock when trying to > send data out a single openssl bufferevent from two separate threads. The > individual threads themselves send complete messages with each write. This > should present no real problem from a synchronization perspective. In fact, > the code works flawlessly when using ordinary bufferevents (not ssl > bufferevents). > Have you enabled OpenSSL locking? OpenSSL uses a myriad of global variables and you have to initalize a set of mutexes and set lock/unlock callbacks via ssl. See https://github.com/ellzey/libevhtp/blob/master/evhtp.c#L3160 as an example. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
Re: [Libevent-users] Simple question about multithreading SSL bufferevents.
You can see the test code at http://pastebin.com/0136vEbe -John - Original Message - From: Mark Ellzey To: libevent-us...@freehaven.net Cc: Sent: Wednesday, March 27, 2013 11:20 AM Subject: Re: [Libevent-users] Simple question about multithreading SSL bufferevents. On Tue, Mar 26, 2013 at 03:32:17PM -0700, John wrote: > I would be happy to share my test code- but it is ~300ish lines due to > (primarily) openssl and thread initialization. Please make a gist or a patebin. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
Re: [Libevent-users] Simple question about multithreading SSL bufferevents.
Nick, I have made my code capable of running multiple sets of single-threaded SSL bufferevent+event_base (i.e. works with current libevent 2.0) as well as able to run fully multithreaded (breaks with current libevent 2.0) I will be happy to test the changes in my real softwarewhich would probably be a better stress test than the simple test software I posted before. Thanks, -John From: Nick Mathewson To: libevent-us...@freehaven.net; John Sent: Thursday, April 25, 2013 11:36 AM Subject: Re: [Libevent-users] Simple question about multithreading SSL bufferevents. On Tue, Mar 26, 2013 at 6:32 PM, John wrote: > Hello all, > > I am having significant issues with (near immediate) deadlock when trying to > send data out a single openssl bufferevent from two separate threads. FWIW, I can confirm that my current "21_deadlock_fix" branch makes your example code run as expected. See the thread "RFC: strategy for deadlock avoidance and safe finalization in Libevent 2.1" from earlier this month for more information on that. I hope to clean it up in the next few days and merge it soon. Ideally, I would like to get the next Libevent 2.1.x-alpha released over this weekend. best wishes, -- Nick *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
[Libevent-users] libevent + curl
I'm trying to modify the hiperfifo.c example included in libcurl (http://curl.haxx.se/libcurl/c/hiperfifo.html ) to use libevent 2.0.20 and had a few questions. I know the originator of this code is the libcurl people but I figured this would be a better place to ask since the questions are more about libevent version differences. This has likely been asked before but I couldn't find a way to search the mailing list. Line 74: The GlobalInfo struct contains 2 event structures. Since the event now(?) appears to be an opaque struct I converted these to event* instead. Line 114 : Curl will pass -1 into the timer callback if there is no timeout. Passing a negative timeout into evtimer_add causes me to get "a Assertion is_same_common_timeout". Blocking the add when timeout is -1 appears to fix the issue. Line 236 : Replaced event_set with f->ev = event_new(g->base, f->sockfd, kind, event_cb, g); Also stored base in GlobalInfo since the original relied on the global base which is apparent not a good thing. Line : 389 : same as above Do these changes make sense? Any other changes that would make this more up to date? At this point it compiles and appears to run without any crashes. Thanks- John *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
RE: [Libevent-users] libevent + curl
From: owner-libevent-us...@freehaven.net [mailto:owner-libevent-us...@freehaven.net] On Behalf Of Mark Ellzey Sent: Monday, October 22, 2012 6:06 PM > Post the resulting code somewhere. I've posted the code here - http://pastebin.com/REca0BTq. I've modified the original allow me to add multiple curl http events on a currently running event base through the add_http method. It hasn't been fully debugged or anything but I'm just curious if the basic idea is sound. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
[Libevent-users] UDP Support
Has there been any progress on UDP support in libevent? The last mention I can find in the email list is from Dec 2010. It sounded like supporting unconnected sockets was going to be difficult in 2.0.x - will any of the changes in 2.1.x make this easier? I'm not familiar enough with libevent to be of any use developing such a feature but would be more than happy to test. Thanks- John *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
RE: [Libevent-users] UDP Support
On Wednesday, December 12, 2012 12:12 PM Nick Mathewson wrote > I'm pretty sure John is asking about UDP support under bufferevents. Actually I was looking for any UDP support - it doesn't have to necessarily use bufferevents. I've figured out how to get UDP working with writing my own socket initialization code but if there was support similar to the TCP libevent support I'd use it - I'd rather not reinvent the wheel. *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.
[Libevent-users] event shutdown/cleanup
I have a socket server which allocates memory for each connection. If there's an error on the socket it's easy for me to delete any memory associated with the connection. I also need to shutdown the eventbase from another thread which needs to close the listener socket, close all currently open connections and delete all memory associated with each connection. If I call event_base_loopbreak and event_base_free to shutdown my event loop the loop breaks but it doesn't close any outstanding connections or give me a chance to delete memory associated with each connection. I am setting BEV_OPT_CLOSE_ON_FREE so I assume that the issue is that the bufferedevents are not getting freed when the event_base is. Is there any libevent functionality that would help or do I need to maintain a parallel data structure of current connections so I can call event_free() on each of them? event_base_foreach_event seems almost like the correct thing but the documentation explicitly says to not modify the events - I'm guessing that includes calling event_free(). Thanks- John *** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-usersin the body.