question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySQL server gone away in Auth middleware

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
heteddycommented, Sep 11, 2018

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_connections

0reactions
andrewgodwincommented, Aug 14, 2018

Yes, this is just the standard Django connection behaviour outside of requests, sorry! Not much we can do other than document it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found