<br><br><div class="gmail_quote">On Wed, Oct 3, 2012 at 4:28 PM, Phil Mayers <span dir="ltr">&lt;<a href="mailto:p.mayers@imperial.ac.uk" target="_blank">p.mayers@imperial.ac.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 10/02/2012 06:09 PM, E S wrote:<br>
&gt; I have a service running that occasionally connects to a MySQL<br>
&gt; database. When there is no activity on it for some time, I eventually<br>
&gt; get the the error<br>
&gt;<br>
&gt; _mysql_exceptions.OperationalError: (2006, &#39;MySQL server has gone away&#39;)<br>
&gt;<br>
&gt; I have found a few posts on this group related to this issue<br>
&gt;<br>
&gt; <a href="http://twistedmatrix.com/pipermail/twisted-python/2007-July/015788.html" target="_blank">http://twistedmatrix.com/pipermail/twisted-python/2007-July/015788.html</a><br>
&gt; <a href="http://twistedmatrix.com/pipermail/twisted-python/2007-October/016178.html" target="_blank">http://twistedmatrix.com/pipermail/twisted-python/2007-October/016178.html</a><br>
&gt;<br>
&gt; as well as some tickets on the twisted homepage:<br>
&gt;<br>
&gt; <a href="http://twistedmatrix.com/trac/ticket/4404" target="_blank">http://twistedmatrix.com/trac/ticket/4404</a><br>
&gt; <a href="http://twistedmatrix.com/trac/ticket/4964" target="_blank">http://twistedmatrix.com/trac/ticket/4964</a><br>
&gt;<br>
&gt; I have also seen this referenced as a potential fix:<br>
&gt;<br>
&gt; <a href="http://www.gelens.org/2009/09/13/twisted-connectionpool-revisited/" target="_blank">http://www.gelens.org/2009/09/13/twisted-connectionpool-revisited/</a><br>
&gt;<br>
&gt; I currently have the cp_reconnect parameter set to True, but it does<br>
&gt; not appear to be doing the job. I don&#39;t really see much consensus on<br>
&gt; how to properly handle this issue. Some people seem to think that the<br>
&gt; cp_reconnect parameter should take care of it for you, other people<br>
&gt; say that cp_reconnect is only part of the solution and that you have<br>
&gt; to write your own error handling.<br>
<br>
</div>For what it&#39;s worth - I think adbapi is seriously sub-optimal in this<br>
regard. We have continual low-level problems with Twisted apps getting<br>
stuck due to hung/dead ConnectionPool. And if you forget cp_reconnect,<br>
well you are basically committing suicide. Your Twisted app will need a<br>
restart.<br>
<br>
In particular - it&#39;s not clear to my why CP isn&#39;t using &quot;cp_good_sql&quot; to<br>
probe a connection *before* starting the transaction, and to<br>
close/re-open it transparently if it has died and cp_reconnect==1.<br>
<br>
Instead, the only place the &quot;good&quot; SQL is run is *after* a rollback, so<br>
the next N transactions into the pool (where N is the number of threads)<br>
all fail, because they don&#39;t get as far as &quot;rollback&quot;.<br>
<br>
I think the behaviour it should be aiming for is clear:<br>
<br>
  1. Test each connection with &quot;good_sql&quot; before beginning the user<br>
interaction/query<br>
  2. If execeptions occur inside the user interaction, either at cursor<br>
methods like execute, or connection methods like commit, then:<br>
     1. rollback - if *this* raises an exception, throw the conn away<br>
     2. propagate the original exception upwards unchanged (maybe<br>
wrapped, maybe not)<br>
<br>
cp_reconnect should be the default.<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>Hi<br><br>  MySQLdb (If you use it) has its own socket wrappers and callings so the only way to co-operate with twisted is to use adbapi. It is possible to use other implementations but there are no one claim production ready.<br>
<br>Regards<br><br>gelin yan<br>