I am encountering this exception (using peewee-async high-level api) then my asyncio based daemon is idle (about 15 minutes or so), after that time, this exception occurs, I have tried to close and reopen connection, and was surprised that Manager (high-level api) did not track its state (close/reopen is done using its methods).
Traceback (most recent call last):
File "/home/ubuntu/dati-server/match/manager.py", line 56, in clean_up_user
await exam_end_all_handler(current_match_id, user_id)
File "/home/ubuntu/dati-server/match/manager.py", line 407, in exam_end_all_handler
match_result = await MatchUserRecord.set_user_score_and_winner(match_id)
File "/home/ubuntu/dati-server/models/record.py", line 260, in set_user_score_and_winner
score1 = await user_record1.get_match_score()
File "/home/ubuntu/dati-server/models/record.py", line 108, in get_match_score
answer_records = await objects.execute(UserAnswerRecord.filter(match_id=self.match.id, user_id=self.user_id))
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 1386, in __get__
return self.get_object_or_id(instance)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 1377, in get_object_or_id
obj = self.rel_model.get(self.field.to_field == rel_id)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 4988, in get
return sq.get()
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 3220, in get
return next(clone.execute())
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 3274, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 2939, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee_async.py", line 1041, in execute_sql
return super().execute_sql(*args, **kwargs)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 3837, in execute_sql
self.commit()
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 3656, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 135, in reraise
raise value.with_traceback(tb)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/peewee.py", line 3830, in execute_sql
cursor.execute(sql, params or ())
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/pymysql/cursors.py", line 165, in execute
result = self._query(query)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/pymysql/connections.py", line 859, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "/home/ubuntu/dati-server/env/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in _execute_command
raise err.InterfaceError("(0, '')")
peewee.InterfaceError: (0, '')
This looks like a bug in peewee-async or something? Some server issue?
Peewee is tested with mysql every release (and every commit for that matter) so I know mysql isn't horribly broken or anything.
The follow up is at https://github.com/05bit/peewee-async/issues/26
We encounter the same problem with peewee with use recent flask version 1.0.2 without relying on flask-peewee.
We do not open/close connection between each request, I was expecting to be able to reuse the connection across request.
We do not use the connection pool.
I think we found the issue. Looking up earlier log, we noticed mysqld server closed the only connection we had and we did not reconnect after.
ref: http://docs.peewee-orm.com/en/latest/peewee/database.html#error-2006-mysql-server-has-gone-away
ref: http://docs.peewee-orm.com/en/latest/peewee/database.html#flask
Ty!
Most helpful comment
I think we found the issue. Looking up earlier log, we noticed mysqld server closed the only connection we had and we did not reconnect after.
ref: http://docs.peewee-orm.com/en/latest/peewee/database.html#error-2006-mysql-server-has-gone-away
ref: http://docs.peewee-orm.com/en/latest/peewee/database.html#flask
Ty!