Git Product home page Git Product logo

Comments (10)

hagsteel avatar hagsteel commented on June 21, 2024

I have not used this with MySQL (I'm using Postgres for my projects), and I don't have this problem with postgres.
Any more information you can give me so I can try to replicate this?
I will setup a test project with MySQL and see if I get this issue.

from swampdragon.

hagsteel avatar hagsteel commented on June 21, 2024

I've created a demo project running a celery task every 2 second updating a self publishing model.
I have five browsers open viewing the page that receives the updates.
So far I have not seen any issues with MySQL but I'll leave it running for a while.

from swampdragon.

mback2k avatar mback2k commented on June 21, 2024

Thanks for trying to re-create my issue. It seems like my MySQL server is running into a connection limit and randomly aborts connections. I get tons of the following errors:

[Warning] Aborted connection $n to db: '$dbname' user: '$user' host: '$host' (Unknown error)

Let me check if I can increase that limit.

from swampdragon.

mback2k avatar mback2k commented on June 21, 2024

Okay, got it. The MySQL wait_timeout parameter was set too low. 600 seconds is not enough for the SwampDragon server. Does it perform any kind of heartbeat operation to keep the database connection open?

from swampdragon.

hagsteel avatar hagsteel commented on June 21, 2024

Currently it doesn't. I would like to know how to replicate this issue.
I'm not overly familiar with MySQL. I set the timeout to a low number but I'm still not getting a timeout.
Could you describe your setup so I can tweak my test project to be more similar (and hopefully get the same issue so I can solve it)?

from swampdragon.

mback2k avatar mback2k commented on June 21, 2024

It seems like increasing wait_time only delays the problem. Here is the my.cnf used for mariadb-server (10.0.13+maria-1~wheezy) and the relevant environment-specific Django config: https://gist.github.com/mback2k/899fced7241f64b50793. The remaining Django config can be found here: https://github.com/mback2k/django-webgcal/tree/master/webgcal/settings.
You said that your celery task actually performs something in the background, so the database connection is actually used. What happens if you disable that task, just connect to the WebSocket once to get some data and then close your browser until wait_timeout is hit? Thanks for investigating this.

from swampdragon.

hagsteel avatar hagsteel commented on June 21, 2024

I've managed to replicate this issue now (thanks for the settings).
It doesn't happen when running with Postgres (and SQLite) which are the only databases I've tried until now.

It wasn't until I added

    'OPTIONS': {
        'init_command': 'SET storage_engine=INNODB',
    }

to settings that this started happening.

I've created a gist for this for now until I figure out what to do in the long run:
https://gist.github.com/jonashagstedt/6113b0e0e9cd4b4c3585

Let me know if that solves the problem.
I've tested this by setting the timeout to a very low number and it works.

Remember to update the connection in settings:

SWAMP_DRAGON_CONNECTION = ('myproject.connection.MysqlHeartbeatConnection', '/data')

from swampdragon.

hagsteel avatar hagsteel commented on June 21, 2024

I ran a very simple test to make sure there wasn't a significant performance loss with this solution (and there wasn't).

The test is very simple and does the following:

  1. Connect 300 clients
  2. Subscribe to a channel
  3. Get a list of models

With the gist provided above, I ran the test five times:
631 ms
624 ms
642 ms
642 ms
616 ms
avg: 631 ms

With the default connection:
639 ms
632 ms
642 ms
641 ms
653 ms
avg: 641 ms

from swampdragon.

mback2k avatar mback2k commented on June 21, 2024

Thanks for providing this workaround. I verified that it also solves the problem for me. I also tried to alternatively set CONN_MAX_AGE to something below wait_timeout, but that alone didn't help. Maybe you want to include that heartbeat into the default connection and make it detect MySQL like this:

if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql':

from swampdragon.

hagsteel avatar hagsteel commented on June 21, 2024

I've thought about it for a bit now and it would be clever to check the DB engine, however the timeout is posing a bit of a problem.
Since the timeout of MySql can differ from environments it's something that needs to be set by the user.

I wrote up a short blog post about it (http://swampdragon.net/blog/mysql-server-has-gone-away/) instead.

Good suggestion though

from swampdragon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.