<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — multithreading with sniffer application - [suggested bug and fix]]]></title>
		<link>https://www.wolfssl.com/forums/topic366-multithreading-with-sniffer-application-suggested-bug-and-fix.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic366.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in multithreading with sniffer application - [suggested bug and fix].]]></description>
		<lastBuildDate>Fri, 10 May 2013 09:52:23 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: multithreading with sniffer application - [suggested bug and fix]]]></title>
			<link>https://www.wolfssl.com/forums/post1067.html#p1067</link>
			<description><![CDATA[<p>you are right, this patch should be under the locked region. thanks for patching! </p><p>Dan</p>]]></description>
			<author><![CDATA[null@example.com (SheldonCooper)]]></author>
			<pubDate>Fri, 10 May 2013 09:52:23 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post1067.html#p1067</guid>
		</item>
		<item>
			<title><![CDATA[Re: multithreading with sniffer application - [suggested bug and fix]]]></title>
			<link>https://www.wolfssl.com/forums/post1065.html#p1065</link>
			<description><![CDATA[<p>Thanks for the patch.&nbsp; I agree with your analysis.&nbsp; The only change I did was to move the bornOn reset into the locked region to prevent an unlikely race condition.&nbsp; Here&#039;s the commit for your reference: <a href="https://github.com/cyassl/cyassl/commit/ca4b2b3f9012847f28b83083140fead0b6716afd">https://github.com/cyassl/cyassl/commit … d0b6716afd</a></p><p>Thanks again.</p>]]></description>
			<author><![CDATA[null@example.com (todd)]]></author>
			<pubDate>Thu, 09 May 2013 18:51:34 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post1065.html#p1065</guid>
		</item>
		<item>
			<title><![CDATA[Re: multithreading with sniffer application - [suggested bug and fix]]]></title>
			<link>https://www.wolfssl.com/forums/post1064.html#p1064</link>
			<description><![CDATA[<p>thanks for your reply - however, I already solved the problem and suggest you patch it if possible:<br />while the session table is thread safe, the usage of ssl_decodePacket <strong>isn&#039;t</strong> thread safe, even if the the same session is always treated by the same thread:<br />note that whenever ssl_decodePacket is called, if syn is encountered the &quot;CreateSession&quot; method is invoked, which in turn calls RemoveStaleSessions. there, &quot;old&quot; sessions are removed, but no one makes sure that another thread is not currently using these &quot;old&quot; sessions. the bug is that currently used sessions are considered &quot;old&quot;. this can be easily fixed by adding the following (one) line to the &quot;GetSnifferSession&quot; method in &quot;sniffer.c&quot; after the session is pointer is acquired and verified as non-null:<br /></p><div class="codebox"><pre><code>static SnifferSession* GetSnifferSession(...){
    ...
    while(session){ //obtaining the session according to ipInfo tcpInfo passed to the function
    }
    unlock(&amp;SessionMutex);
    if(session){ //checking if a session was actually found
       .... 
       session-&gt;bornOn = time(NULL); ///******* new code ! *********// &lt;--------------------
    }
}</code></pre></div><p>this patch allows <strong>multithreaded use of ssl_decodePacket</strong> (assuming of course session-wise load balancing between the threads), and will not cause thread X to free a session thread Y is currently working on.<br />in addition, this also fixes a functionality problem (as I see it...), you don&#039;t really want to throw away a session SNIFFER_TIMEOUT seconds from arrival time, but only if the session was silent for SNIFFER_TIMEOUT.</p><p>what do you think?</p><p>regards,<br />Dan</p>]]></description>
			<author><![CDATA[null@example.com (SheldonCooper)]]></author>
			<pubDate>Thu, 09 May 2013 08:59:09 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post1064.html#p1064</guid>
		</item>
		<item>
			<title><![CDATA[Re: multithreading with sniffer application - [suggested bug and fix]]]></title>
			<link>https://www.wolfssl.com/forums/post1056.html#p1056</link>
			<description><![CDATA[<p>Hi Dan,</p><p>Access to the sniffer session table is thread safe.&nbsp; What isn&#039;t thread safe, is using the same sniffer session from multiple threads.&nbsp; For example, say sniffer session A is created by thread X. If 3 new packets come in for session A and threads X, Y, and Z all try to handle those packets concurrently that&#039;s a problem.&nbsp; Ideally, you&#039;re main thread would associate an ssl sniffer session (client ip/client port &lt;-&gt; server ip/server port) with a particular thread and use that same thread for the lifetime of the session.&nbsp; Short of that, the sniffer session would need a lock which isn&#039;t ideal in your scenario because once thread X locks the first packet from session A threads Y and Z would be blocked until thread X is done.&nbsp; That defeats the whole purpose of what you&#039;re trying to accomplish.&nbsp; Does that information help?</p><p>-Todd</p>]]></description>
			<author><![CDATA[null@example.com (todd)]]></author>
			<pubDate>Mon, 06 May 2013 21:02:51 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post1056.html#p1056</guid>
		</item>
		<item>
			<title><![CDATA[Re: multithreading with sniffer application - [suggested bug and fix]]]></title>
			<link>https://www.wolfssl.com/forums/post1046.html#p1046</link>
			<description><![CDATA[<p>just a note:<br />I know I am not using solely the sniffer application, and it&#039;s most possible the error is in my addition of the multithreading, I have looked at it hard before posting. If you feel this question is out of place in the forum I completely understand. just a reply of whether my understanding of &quot;snifferServer&quot; is correct would suffice if you are not able to elaborate...</p><br /><p>thanks,<br />Dan</p>]]></description>
			<author><![CDATA[null@example.com (SheldonCooper)]]></author>
			<pubDate>Wed, 01 May 2013 14:01:15 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post1046.html#p1046</guid>
		</item>
		<item>
			<title><![CDATA[multithreading with sniffer application - [suggested bug and fix]]]></title>
			<link>https://www.wolfssl.com/forums/post1045.html#p1045</link>
			<description><![CDATA[<p>Hey all,<br />I monitor my own server and use the wolfSSL embedded ssl sniffer application using my server&#039;s private key. I register my server using ssl_setPrivateKey and do this only once (since i have only one server i monior). then, I call ssl_decodePacket for each packet. everything works just fine. recently, I tried to multithread the sniffer - I spawn some threads and call ssl_decodePacket from multiple threads. as far as i can see, the session table is thread safe, and it seems the application as a whole is built for it. however, I seem to crush when I ssl_decodePacket in a multithreaded fashion. I suspect it has to do with the fact that all the sessions to my server are using the same SnifferServer object, although, as I imagine, that has to be the case since I have only one server, accepting traffic on port 443. </p><p>I know SnifferServer is not being freed, this isn&#039;t the problem - I know it&#039;s quite general, but, any ideas?</p><p>sure, I can use the program with one thread, but I find the multithreaded version much faster to go over large data sets.</p><p>thanks,<br />Dan</p>]]></description>
			<author><![CDATA[null@example.com (SheldonCooper)]]></author>
			<pubDate>Wed, 01 May 2013 13:57:17 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post1045.html#p1045</guid>
		</item>
	</channel>
</rss>
