Hi,<br>
<br>
Thanks for the answer.<br>
<br>
The problem is that when create a Store object, storm does not try to
connect right away so no exception is thrown at that point. When there
is a need, storm try to use the connection and fail. To handle it, I
have to wrap many try: catch exception all over places and not quite
sure where and it does not look good.<br>
<br>
Like a php mysql db, they just don't care, if connection goes away, they
reconnect / make new connection automatically. That would be be nice<br><br><br><br><div class="gmail_quote">On Wed, Jan 26, 2011 at 6:37 PM, Jamu Kakar <span dir="ltr"><<a href="mailto:jkakar@kakar.ca">jkakar@kakar.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Steve,<br>
<div class="im"><br>
On Wed, Jan 26, 2011 at 9:31 AM, Steve Kieu <<a href="mailto:msh.computing@gmail.com">msh.computing@gmail.com</a>> wrote:<br>
> I am developing a simple WSGI application using storm and MySQL. The problem<br>
> is, after midnight ; or for some reason I restart MySQL server and my<br>
> application dies with 500 - and inside I have exception by Storm raised:<br>
><br>
> [Sun Jan 23 08:23:10 2011] [error] [client 169.173.0.179] File<br>
> "/usr/local/lib/python2.6/dist-packages/storm/databases/mysql.py", line 106,<br>
> in execute<br>
> [Sun Jan 23 08:23:10 2011] [error] [client 169.173.0.179] return<br>
> Connection.execute(self, statement, params, noresult)<br>
> [Sun Jan 23 08:23:10 2011] [error] [client 169.173.0.179] File<br>
> "/usr/local/lib/python2.6/dist-packages/storm/database.py", line 227, in<br>
> execute<br>
> [Sun Jan 23 08:23:10 2011] [error] [client 169.173.0.179]<br>
> self._ensure_connected()<br>
> [Sun Jan 23 08:23:10 2011] [error] [client 169.173.0.179] File<br>
> "/usr/local/lib/python2.6/dist-packages/storm/database.py", line 344, in<br>
> _ensure_connected<br>
> [Sun Jan 23 08:23:10 2011] [error] [client 169.173.0.179] raise<br>
> DisconnectionError("Already disconnected")<br>
><br>
> Sometimes I got the error mesasge like ; MySQL has gonna away ....<br>
<br>
</div>This is the expected behaviour. When the underlying database goes<br>
away (or is restarted) and an existing connection is used, Storm will<br>
raise a DisconnectionError. It's up to your application to detect<br>
this and determine how to recover. In the case of a web server you<br>
can usually just retry the request being handled. Be careful to put a<br>
maximum retry limit. If the database doesn't come back quickly you<br>
don't want to be continuously retrying requests.<br>
<div class="im"><br>
> To fix, just restart apache.<br>
<br>
</div>This works because Storm is creating new connections to MySQL when you<br>
<div class="im">restart Apache.<br>
<br>
> The problem is that storm tried to use existing connection and the server is<br>
> gone. Storm does not want to reinitialize the connection but raise<br>
> exception. In my code it is clearly that for each request I create a dsn and<br>
> a Store object like store = Store(create_database(dsn)). Unfortunately it<br>
> still reuse the connection somehow and then dies. (probably the python<br>
> environment is reusing these variable somehow)<br>
<br>
</div>Storm will raise a DisconnectionError, as a signal that the<br>
transaction failed and you need to recover. If you try to use the<br>
connection again Storm will attempt to reconnect to the database<br>
automatically. If that fails, it'll raise DisconnectionError again.<br>
<div class="im"><br>
> To prove that is the issue I took a cgi to wsgi gateway from python PEP<br>
> somewhere, fix it a bit so I can convert the whole wsgi to use cgi. Now<br>
> problem goes away, I can restart mysql server but the application still<br>
> works as expected.<br>
<br>
</div>Yep, this is because the CGI application is opening a new connection<br>
to the database for each request. If the database disappeared during<br>
the CGI request you'd see the same exception.<br>
<br>
Thanks,<br>
<font color="#888888">J.<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Steve Kieu<br>