peewee-async: peewee.InterfaceError: (0, '') | pymysql.err.InterfaceError: (0, '')
I am encountering this exception (using 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).
after reopening a connection I’ve got stuck with a bunch of coroutines waiting for resolution which obviously will never come. =(
- can it be a bug in pymysql/peewee
- propose add connection status tracking to high-level Manager
any thoughts on how to fix that?
Traceback (most recent call last):
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 3748, in execute_sql
warehouse_1 | cursor.execute(sql, params or ())
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
warehouse_1 | result = self._query(query)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
warehouse_1 | conn.query(q)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/connections.py", line 851, in query
warehouse_1 | self._execute_command(COMMAND.COM_QUERY, sql)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/connections.py", line 1067, in _execute_command
warehouse_1 | raise err.InterfaceError("(0, '')")
warehouse_1 | pymysql.err.InterfaceError: (0, '')
warehouse_1 |
warehouse_1 | During handling of the above exception, another exception occurred:
warehouse_1 |
warehouse_1 | Traceback (most recent call last):
warehouse_1 | File "/opt/app/storage/sql.py", line 357, in _wrapper_catch_db_excetions
warehouse_1 | return await fn(*args, **kwargs)
warehouse_1 | File "/opt/app/storage/sql.py", line 415, in update
warehouse_1 | await self._manager.create(Item2Source, item_id=existing.id, source_id=source.id)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee_async.py", line 183, in create
warehouse_1 | pk = inst._get_pk_value()
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 5017, in _get_pk_value
warehouse_1 | return getattr(self, self._meta.primary_key.name)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 1553, in __get__
warehouse_1 | for field_name in self.field_names])
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 1553, in <listcomp>
warehouse_1 | for field_name in self.field_names])
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 1363, in __get__
warehouse_1 | return self.get_object_or_id(instance)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 1354, in get_object_or_id
warehouse_1 | obj = self.rel_model.get(self.field.to_field == rel_id)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 4900, in get
warehouse_1 | return sq.get()
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 3161, in get
warehouse_1 | return next(clone.execute())
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 3213, in execute
warehouse_1 | self._qr = ResultWrapper(model_class, self._execute(), query_meta)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 2892, in _execute
warehouse_1 | return self.database.execute_sql(sql, params, self.require_commit)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee_async.py", line 1024, in execute_sql
warehouse_1 | return super().execute_sql(*args, **kwargs)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 3755, in execute_sql
warehouse_1 | self.commit()
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 3578, in __exit__
warehouse_1 | reraise(new_type, new_type(*exc_args), traceback)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 135, in reraise
warehouse_1 | raise value.with_traceback(tb)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/peewee.py", line 3748, in execute_sql
warehouse_1 | cursor.execute(sql, params or ())
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 166, in execute
warehouse_1 | result = self._query(query)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 322, in _query
warehouse_1 | conn.query(q)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/connections.py", line 851, in query
warehouse_1 | self._execute_command(COMMAND.COM_QUERY, sql)
warehouse_1 | File "/usr/local/lib/python3.5/site-packages/pymysql/connections.py", line 1067, in _execute_command
warehouse_1 | raise err.InterfaceError("(0, '')")
warehouse_1 | peewee.InterfaceError: (0, '')
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 15 (3 by maintainers)
I am also encountering this. I use flask with socketio, which, as far as I know, uses coroutines or something similar. Maybe it is connected to async, after all?
I am not using anything fancy from peewee - just the high level API. And indeed, it happens after long idle time.
Edit: Looks like I got the wrong repo, I’m actually using normal peewee. This is still an issue for me, though. Maybe this will help you narrow it down.
my test is designed to show what bug appears in simple, real-world scenario, “crazy-monkey method” to speed up tests - is just a way of getting work done faster =)
Here is another thing which can help to track the cause - in all variations of code and execution graphs - it always fail while working with
Item2Source
- which is not like other 2 models - it is a many2many table relation (composed of 2 foreignkey fields and having them as composite pk)I am not familiar with peewee internals but it looks connected.
according to this tread: http://stackoverflow.com/questions/6650940/interfaceerror-0 this is related to unreleased cursors somehow.
here I must mention what I use
Manager.atomic()
context manager, maybe there is a problem in releasing cursors due to following statement:do context manager releases cursors after exiting a transaction?