[GH-ISSUE #660] Cron jobs trigger warning about non-standard shutdown of database connection (MySQL) #616

Closed
opened 2026-02-27 11:12:41 +03:00 by kerem · 26 comments
Owner

Originally created by @smarek on GitHub (Dec 15, 2014).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/660

Running the cronjobs (no matter under what account) triggers warning in syslog, like this

Dec 15 13:51:01 {hostname} mysqld: 141215 13:51:01 [Warning] Aborted connection {conn_id} to db: '{db_name}' user: '{db_user}' host: '{db_host}' (Unknown error)

example cronjob definition

0 0 * * * python /{modoboa_instance_path}/manage.py cleanlogs

Is this known issue, or problem of instance configuration?
I'm not running it in virtualenv or anything special.

Originally created by @smarek on GitHub (Dec 15, 2014). Original GitHub issue: https://github.com/modoboa/modoboa/issues/660 Running the cronjobs (no matter under what account) triggers warning in syslog, like this ``` Dec 15 13:51:01 {hostname} mysqld: 141215 13:51:01 [Warning] Aborted connection {conn_id} to db: '{db_name}' user: '{db_user}' host: '{db_host}' (Unknown error) ``` example cronjob definition ``` 0 0 * * * python /{modoboa_instance_path}/manage.py cleanlogs ``` Is this known issue, or problem of instance configuration? I'm not running it in virtualenv or anything special.
kerem closed this issue 2026-02-27 11:12:41 +03:00
Author
Owner

@tonioo commented on GitHub (Dec 15, 2014):

Hi,
do you observe this behaviour with every cron job or just this one ?

<!-- gh-comment-id:67002182 --> @tonioo commented on GitHub (Dec 15, 2014): Hi, do you observe this behaviour with every cron job or just this one ?
Author
Owner

@smarek commented on GitHub (Dec 15, 2014):

All of them, could this bugreport be related? https://code.djangoproject.com/ticket/21255

<!-- gh-comment-id:67011147 --> @smarek commented on GitHub (Dec 15, 2014): All of them, could this bugreport be related? https://code.djangoproject.com/ticket/21255
Author
Owner

@tonioo commented on GitHub (Dec 15, 2014):

Maybe. I already found this issue and the cleanlogs command (the one you mentionned in your exampe) already closes the connection manually so I don't really understand.

<!-- gh-comment-id:67012776 --> @tonioo commented on GitHub (Dec 15, 2014): Maybe. I already found this issue and the cleanlogs command (the one you mentionned in your exampe) already closes the connection manually so I don't really understand.
Author
Owner

@tonioo commented on GitHub (Dec 15, 2014):

What's your distribution? MySQL version?

<!-- gh-comment-id:67024281 --> @tonioo commented on GitHub (Dec 15, 2014): What's your distribution? MySQL version?
Author
Owner

@smarek commented on GitHub (Dec 16, 2014):

I've just checked the logs, aborted connection warning appears after logparser,handle_mailbox_operations and cleanlogs.

My distribution is Debian Wheezy 7.7 x86_64, with MariaDB 10.1.2

<!-- gh-comment-id:67154788 --> @smarek commented on GitHub (Dec 16, 2014): I've just checked the logs, aborted connection warning appears after `logparser`,`handle_mailbox_operations` and `cleanlogs`. My distribution is Debian Wheezy 7.7 x86_64, with MariaDB 10.1.2
Author
Owner

@tonioo commented on GitHub (Dec 17, 2014):

Can you give me the version of the mysql python driver installed on your environment please ?

<!-- gh-comment-id:67340735 --> @tonioo commented on GitHub (Dec 17, 2014): Can you give me the version of the mysql python driver installed on your environment please ?
Author
Owner

@smarek commented on GitHub (Dec 17, 2014):

That would be:

server-shell# dpkg -l | grep -i python | grep -i sql
ii  python-mysqldb                     1.2.3-2                         amd64        Python interface to MySQL
server-shell# apt-cache policy python-mysqldb
python-mysqldb:
  Installed: 1.2.3-2
  Candidate: 1.2.3-2
  Version table:
 *** 1.2.3-2 0
        600 http://ftp.debian.org/debian/ wheezy/main amd64 Packages
        100 /var/lib/dpkg/status
     1.2.2-10+b1 0
        500 http://http.debian.net/debian/ squeeze/main amd64 Packages
<!-- gh-comment-id:67341246 --> @smarek commented on GitHub (Dec 17, 2014): That would be: ``` server-shell# dpkg -l | grep -i python | grep -i sql ii python-mysqldb 1.2.3-2 amd64 Python interface to MySQL server-shell# apt-cache policy python-mysqldb python-mysqldb: Installed: 1.2.3-2 Candidate: 1.2.3-2 Version table: *** 1.2.3-2 0 600 http://ftp.debian.org/debian/ wheezy/main amd64 Packages 100 /var/lib/dpkg/status 1.2.2-10+b1 0 500 http://http.debian.net/debian/ squeeze/main amd64 Packages ```
Author
Owner

@tonioo commented on GitHub (Dec 17, 2014):

It is not the latest version (https://pypi.python.org/pypi/MySQL-python/1.2.5).

Could you try with a newest version ?

<!-- gh-comment-id:67341885 --> @tonioo commented on GitHub (Dec 17, 2014): It is not the latest version (https://pypi.python.org/pypi/MySQL-python/1.2.5). Could you try with a newest version ?
Author
Owner

@smarek commented on GitHub (Dec 19, 2014):

Just tested, the same warning appears with 1.2.5 version

<!-- gh-comment-id:67688893 --> @smarek commented on GitHub (Dec 19, 2014): Just tested, the same warning appears with 1.2.5 version
Author
Owner

@smarek commented on GitHub (Dec 19, 2014):

I probably found the issue, if the script is failing with trace it won't shut down the connection properly

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/modoboa/extensions/stats/management/commands/logparser.py", line 374, in handle
    p.process()
  File "/usr/local/lib/python2.7/dist-packages/modoboa/extensions/stats/management/commands/logparser.py", line 349, in process
    self._parse_line(line)
  File "/usr/local/lib/python2.7/dist-packages/modoboa/extensions/stats/management/commands/logparser.py", line 334, in _parse_line
    self.inc_counter(addrto.group(2), 'recv')
AttributeError: 'NoneType' object has no attribute 'group'
<!-- gh-comment-id:67692120 --> @smarek commented on GitHub (Dec 19, 2014): I probably found the issue, if the script is failing with trace it won't shut down the connection properly ``` Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/modoboa/extensions/stats/management/commands/logparser.py", line 374, in handle p.process() File "/usr/local/lib/python2.7/dist-packages/modoboa/extensions/stats/management/commands/logparser.py", line 349, in process self._parse_line(line) File "/usr/local/lib/python2.7/dist-packages/modoboa/extensions/stats/management/commands/logparser.py", line 334, in _parse_line self.inc_counter(addrto.group(2), 'recv') AttributeError: 'NoneType' object has no attribute 'group' ```
Author
Owner

@smarek commented on GitHub (Dec 19, 2014):

Line 333 patched
from:

if m.group(2) == "sent":

to:

if addrto is not None and m.group(2) == "sent":
<!-- gh-comment-id:67692234 --> @smarek commented on GitHub (Dec 19, 2014): Line 333 patched from: ``` python if m.group(2) == "sent": ``` to: ``` python if addrto is not None and m.group(2) == "sent": ```
Author
Owner

@smarek commented on GitHub (Dec 19, 2014):

Also python /{app_path}/manage.py handle_mailbox_operations -v 3 --traceback is giving no output, just the warning in syslog about not properly shut down db connection

<!-- gh-comment-id:67692413 --> @smarek commented on GitHub (Dec 19, 2014): Also `python /{app_path}/manage.py handle_mailbox_operations -v 3 --traceback` is giving no output, just the warning in syslog about not properly shut down db connection
Author
Owner

@tonioo commented on GitHub (Dec 20, 2014):

It seems you found an issue with the logparser command but it does not fix the database warning...

Have you tried to comment the db.close_connection line?

<!-- gh-comment-id:67736326 --> @tonioo commented on GitHub (Dec 20, 2014): It seems you found an issue with the logparser command but it does not fix the database warning... Have you tried to comment the `db.close_connection` line?
Author
Owner

@smarek commented on GitHub (Dec 20, 2014):

I've now tried, commenting out the line, does no difference to behavior.

<!-- gh-comment-id:67740990 --> @smarek commented on GitHub (Dec 20, 2014): I've now tried, commenting out the line, does no difference to behavior.
Author
Owner

@tonioo commented on GitHub (Dec 21, 2014):

I've tried a fix... Could you please try one more time?

<!-- gh-comment-id:67770318 --> @tonioo commented on GitHub (Dec 21, 2014): I've tried a fix... Could you please try one more time?
Author
Owner

@smarek commented on GitHub (Dec 21, 2014):

Thanks a lot, could you please instruct me how to properly run the git version? Cannot find that in documentation, so I'm stuck with released eggs.

<!-- gh-comment-id:67770343 --> @smarek commented on GitHub (Dec 21, 2014): Thanks a lot, could you please instruct me how to properly run the git version? Cannot find that in documentation, so I'm stuck with released eggs.
Author
Owner

@tonioo commented on GitHub (Dec 21, 2014):

Using pip, try something like this:

$ pip install -e git+https://github.com/tonioo/modoboa#egg=modoboa
$ cd modoboa
$ python setup.py install

(don't forget to load you virtualenv if you use one)

<!-- gh-comment-id:67770455 --> @tonioo commented on GitHub (Dec 21, 2014): Using pip, try something like this: ``` bash $ pip install -e git+https://github.com/tonioo/modoboa#egg=modoboa $ cd modoboa $ python setup.py install ``` (don't forget to load you virtualenv if you use one)
Author
Owner

@smarek commented on GitHub (Dec 21, 2014):

Sincerely no, that didn't helped. Warning stays the same.
Thank you for git install instructions.

<!-- gh-comment-id:67770687 --> @smarek commented on GitHub (Dec 21, 2014): Sincerely no, that didn't helped. Warning stays the same. Thank you for git install instructions.
Author
Owner

@tonioo commented on GitHub (Dec 21, 2014):

Hum.. So it seems I can't solve this issue. I'm running MySQL on several instances and I don't see this warning (because it is just a warning: http://dev.mysql.com/doc/refman/5.0/en/communication-errors.html). Maybe a weird problem on Django's side...

Are you sure you have updated the right python files?

<!-- gh-comment-id:67770917 --> @tonioo commented on GitHub (Dec 21, 2014): Hum.. So it seems I can't solve this issue. I'm running MySQL on several instances and I don't see this warning (because it is just a warning: http://dev.mysql.com/doc/refman/5.0/en/communication-errors.html). Maybe a weird problem on Django's side... Are you sure you have updated the right python files?
Author
Owner

@smarek commented on GitHub (Dec 21, 2014):

I'm running MariaDB 5.5 and 10.1 instances.
I've uninstalled modoboa and installed by your instructions, so I assume it is fully updated?

<!-- gh-comment-id:67770978 --> @smarek commented on GitHub (Dec 21, 2014): I'm running MariaDB 5.5 and 10.1 instances. I've uninstalled modoboa and installed by your instructions, so I assume it is fully updated?
Author
Owner

@tonioo commented on GitHub (Dec 21, 2014):

Yes, it seems so...

<!-- gh-comment-id:67774346 --> @tonioo commented on GitHub (Dec 21, 2014): Yes, it seems so...
Author
Owner

@tonioo commented on GitHub (Dec 24, 2014):

Have you defined the CONN_MAX_AGE setting ?

<!-- gh-comment-id:68053744 --> @tonioo commented on GitHub (Dec 24, 2014): Have you defined the `CONN_MAX_AGE` setting ?
Author
Owner

@tonioo commented on GitHub (Dec 24, 2014):

Ok, I can reproduce it now (increasing MySQL log level).

<!-- gh-comment-id:68054520 --> @tonioo commented on GitHub (Dec 24, 2014): Ok, I can reproduce it now (increasing MySQL log level).
Author
Owner

@smarek commented on GitHub (Dec 25, 2014):

I have not, is it necessary, because the connections are dying in seconds from starting the manage.py process.

Great you can reproduce that, i'll be waiting for follow up +1

<!-- gh-comment-id:68112201 --> @smarek commented on GitHub (Dec 25, 2014): I have not, is it necessary, because the connections are dying in seconds from starting the manage.py process. Great you can reproduce that, i'll be waiting for follow up +1
Author
Owner

@tonioo commented on GitHub (Dec 29, 2014):

Could you try this new fix please?

<!-- gh-comment-id:68249031 --> @tonioo commented on GitHub (Dec 29, 2014): Could you try this new fix please?
Author
Owner

@smarek commented on GitHub (Feb 4, 2015):

I'm sorry it took so long. Yes, the error is now gone, with installing 1.2.0 stable from pypi or github tag.

<!-- gh-comment-id:72904987 --> @smarek commented on GitHub (Feb 4, 2015): I'm sorry it took so long. Yes, the error is now gone, with installing 1.2.0 stable from pypi or github tag.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#616
No description provided.