Consider this code:

1) connect
2) start transaction
3) insert a record
4) select
5) insert another record
6) close transaction

If the connection is lost between 4 and 5 and you reconnect what
should the workflow be? Jump to 1? Jump to 6? Should 5 be executed if
3 was not committed?

I do not believe this reconnection can be automated because depends on
your workflow. Connections should not break.


On Jun 15, 2:58 am, Álvaro J. Iradier <[email protected]> wrote:
> I agree there's not way to notify web2py that the connection is lost,
> but isn't it possible to detect that the connection broke after the
> error is raised, and try to reconnect?
>
> Thanks.
>
> On 15 jun, 03:25, Massimo Di Pierro <[email protected]>
> wrote:
>
>
>
>
>
>
>
> > This presents logical problems. It just should not happen. Edit the
> > mysql config file and change the timeout. If the database is
> > restarted, web2py needs restarting because there is no mechanism in
> > the database connection API to notify web2py (or python) that a
> > connection lost.
>
> > On Jun 14, 4:06 pm, Álvaro J. Iradier <[email protected]> wrote:
>
> > > As seen in this thread:
>
> > >http://groups.google.com/group/web2py/browse_thread/thread/c6653dadbe...
>
> > > I'm getting "broken pipe" messages when mysql is restarted, and under
> > > other circunstances.
>
> > > Going to a shell, I tried doing a query, for example:
>
> > > >>> db(db.location).select()
>
> > > <gluon.dal.Rows object at 0xa2056ec>
>
> > > everything goes ok. Then I restart Mysql, and running the same query I
> > > get:
>
> > > >>> db(db.location).select()
>
> > > Traceback (most recent call last):
> > >   File "<console>", line 1, in <module>
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 5382, in
> > > select
> > >     return self.db._adapter.select(self.query,fields,attributes)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1159, in
> > > select
> > >     rows = response(sql)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1149, in
> > > response
> > >     self.execute(sql)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1234, in
> > > execute
> > >     return self.log_execute(*a, **b)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1229, in
> > > log_execute
> > >     ret = self.cursor.execute(*a,**b)
> > >   File "/var/www/web2py_klnetcenter/gluon/contrib/pymysql/cursors.py",
> > > line 108, in execute
> > >     self.errorhandler(self, exc, value)
> > >   File "/var/www/web2py_klnetcenter/gluon/contrib/pymysql/
> > > connections.py", line 184, in defaulterrorhandler
> > >     raise errorclass, errorvalue
> > > OperationalError: (2013, 'Lost connection to MySQL server during
> > > query')
>
> > > trying to run it again, I only get:
>
> > > >>> db(db.location).select()
>
> > > Traceback (most recent call last):
> > >   File "<console>", line 1, in <module>
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 5382, in
> > > select
> > >     return self.db._adapter.select(self.query,fields,attributes)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1159, in
> > > select
> > >     rows = response(sql)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1149, in
> > > response
> > >     self.execute(sql)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1234, in
> > > execute
> > >     return self.log_execute(*a, **b)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1229, in
> > > log_execute
> > >     ret = self.cursor.execute(*a,**b)
> > >   File "/var/www/web2py_klnetcenter/gluon/contrib/pymysql/cursors.py",
> > > line 108, in execute
> > >     self.errorhandler(self, exc, value)
> > >   File "/var/www/web2py_klnetcenter/gluon/contrib/pymysql/
> > > connections.py", line 182, in defaulterrorhandler
> > >     raise Error(errorclass, errorvalue)
> > > Error: (<class 'socket.error'>, error(32, 'Broken pipe'))
>
> > > forever!. However, if I do:
>
> > > >>> db._adapter.connection.ping()
> > > True
> > > >>> db(db.location).select()
>
> > > <gluon.dal.Rows object at 0xa20596c>
>
> > > so it looks like pinging does a reconnect.
>
> > > If the connection is closed manually, it won't reconnect either:
>
> > > >>> db(db.location).select()
>
> > > <gluon.dal.Rows object at 0xa205a0c>>>> db._adapter.connection.close()
> > > >>> print db(db.location).select()
>
> > > Traceback (most recent call last):
> > >   File "<console>", line 1, in <module>
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 5382, in
> > > select
> > >     return self.db._adapter.select(self.query,fields,attributes)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1159, in
> > > select
> > >     rows = response(sql)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1149, in
> > > response
> > >     self.execute(sql)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1234, in
> > > execute
> > >     return self.log_execute(*a, **b)
> > >   File "/var/www/web2py_klnetcenter/gluon/dal.py", line 1229, in
> > > log_execute
> > >     ret = self.cursor.execute(*a,**b)
> > >   File "/var/www/web2py_klnetcenter/gluon/contrib/pymysql/cursors.py",
> > > line 108, in execute
> > >     self.errorhandler(self, exc, value)
> > >   File "/var/www/web2py_klnetcenter/gluon/contrib/pymysql/
> > > connections.py", line 184, in defaulterrorhandler
> > >     raise errorclass, errorvalue
> > > InterfaceError: (0, '')
>
> > > forever again!
>
> > > Is this the expected behavior? Is web2py or the adapter not detecting
> > > it is not connected and not trying to reconnect unless you ping the
> > > connection?
>
> > > I think this needs fixing. I have a long running shell process, and
> > > every night I find it stopped working and "broken pipe" errors are all
> > > around... I'm trying to workaround it pinging the connection, but I
> > > think that's not a good fix...
>
> > > Greets.

Reply via email to