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 has gone away' is raised when connection goes stale while adding to 'apscheduler_jobs'

See original GitHub issue

When connection goes stale either because of non usage or MySQL restart, following error is raised,

1805 2017-09-26 13:39:03,396 [ERROR] sm_lib [__init__.py:56] [write_error]: (_mysql_exceptions.OperationalError) (2006, 'MySQL server has gone away') [SQL: u'INSERT INTO apscheduler_jobs (id, next_run_time, job_state) VALUES (%s, %s, %s)'] [parameters: ('f01b7658d8ae499fb86b9038f9ffc3c6', 1506450600.0, "\x80\x02}q\x01(U\x04argsq\x02\x8a\x01\x19\x85q\x03U\x08executorq\x04U\x07defaultq\x05U\rmax_instancesq\x06K\x01U\x04funcq\x07U:aps_scheduler.scheduler.executer.campaign:campaign_triggerq\x08U\x02idq\tU f01b7658d8ae499fb86b9038f9ffc3c6q\nU\rnext_run_timeq\x0bcdatetime\ndatetime\nq\x0cU\n\x07\xe1\t\x1a\x12\x1e\x00\x00\x00\x00cpytz\n_UTC\nq\r)Rq\x0e\x86Rq\x0fU\x04nameq\x10U\x10campaign_triggerq\x11U\x12misfire_grace_timeq\x12M\x84\x03U\x07triggerq\x13capscheduler.triggers.date\nDateTrigger\nq\x14)\x81q\x15}q\x16(U\x07versionq\x17K\x01U\x08run_dateq\x18h\x0cU\n\x07\xe1\t\x1a\r'\x03\x05\x94mcpytz\n_p\nq\x19U\x07Etc/UTCq\x1a\x85Rq\x1b\x86Rq\x1cubU\x08coalesceq\x1d\x89h\x17K\x01U\x06kwargsq\
 x1e}q\x1fu.")]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jkryanchoucommented, Nov 4, 2017

@pranav93 Yeah. It works well for me.

0reactions
MDMSevercommented, Mar 22, 2021

For now I’ve added ping_connection in CustomJobStore which is inheriting from SQLAlchemyJobStore.

class MySQLAlchemyJobStore(SQLAlchemyJobStore):

    def __init__(self, *args, **kwargs):
        pool_pre_ping = kwargs.pop('pool_pre_ping', False)
        super(MySQLAlchemyJobStore, self).__init__(*args, **kwargs)
        if pool_pre_ping:
            event.listen(self.engine, "engine_connect", ping_connection)

Refer to http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic And http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic

Hello! I need a bit of help here. I want to use this MySQLAlchemyJobStore instead of the default SQLAlchemyJobStore since I get this ‘2006’ error a lot. I notice function ‘ping_connection()’ is defined at the first link above. But where do I get “some_engine” from… seems that self.engine won’t work… I thought the engine gets created inside the SQLAlchemyJobStore function.

I don’t know where to start in the SQLAlchemy documentation - a concrete example would be best for me - what am I missing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

apscheduler Lost connection to MySQL server during query
I use apscheduler to execute regular job, and I got some error on it. ... To find the answer, I try some test...
Read more >
Resolve the error "MySQL server has gone away" when ...
If a connection is idle for too long, then the connection might be terminated incorrectly from the client. To resolve this issue, verify...
Read more >
APScheduler Documentation
Configuring the job stores and executors is done through the scheduler, as is adding, modifying and removing jobs. 1.1.4 Choosing the right ...
Read more >
Version history — APScheduler 3.9.1 documentation
Fixed a problem where bound methods added as jobs via textual references were called with an unwanted extra self argument (PR by Pengjie...
Read more >
7 Ways to Execute Scheduled Jobs with Python
APScheduler offers three basic scheduling systems that should meet most of your job scheduler needs: Cron-style scheduling (with optional start/end times) ...
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