MySQL server gone away in Auth middleware
See original GitHub issueWhen I run django-channels after a when with daphne, I have found some error about auth middleware.
ERROR Exception inside application: (2006, 'MySQL server has gone away')
AND it failed at
File "/app/python/lib/python3.6/site-packages/channels/auth.py", line 27, in get_user
I have try to add database_sync_to_async to all the method needs to access to the username , and call close_connection in my own middleware before the auth middleware. But there still comes the error.
It is there a bug in auth middleware?What should I do to avoid this problem?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
"MySQL server has gone away" error - Solution(s)
The MySQL server has gone away error, which means that the MySQL server (mysqld) timed out and closed the connection. By default, MySQL...
Read more >B.3.2.7 MySQL server has gone away
The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection. In...
Read more >Laravel 5.6 MySQL Server has gone away - Stack Overflow
I have a basic Laravel application that was working just fine. I ran a php artisan make:auth on it, migrated, registered a new...
Read more >MySQL Database ('2006, 'MySQL server has gone away') error
Hi PythonAnywhere,. We are having some trouble with the "OperationalError: (2006, 'MySQL server has gone away')" error, even though we have ...
Read more >Intentionally get a "MySQL server has gone away" error-django
<?php $mysql = new mysqli("127.0.0.1", "user", "password", "database"); //should be changed to yours while (1) { $r = $mysql->query("SHOW PROCESSLIST"); while ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

the root cause is that django will close old connections(which closed by MySql) each request and response; while in django channels no request trigger close old connections then the database connection will be disconnected by MySQL, so we should do it by yourself;
#channels, before access database
from django.db import close_old_connections close_old_connectionsYes, this is just the standard Django connection behaviour outside of requests, sorry! Not much we can do other than document it.