#942 ✓resolved
Phillip Liu

do_mysql not reconnecting

Reported by Phillip Liu | July 1st, 2009 @ 05:25 PM | in 0.10.0

DB reconnect fails in do_mysql-0.9.12. The trace is provided below.

mysql --version

mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (x86_64) using readline 5.0

I took a look at do_mysql_ext.c and found a couple of problems with how reconnect option is implemented:

  1. On line 538, the '#ifdef MYSQL_OPT_RECONNECT' statement is never true since MYSQL_OPT_RECONNECT is a C enum in my mysql.h. From /usr/include/mysql/mysql.h:
    ... enum mysql_option
    { MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE, MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT }; ...

  2. On line 540, mysql_options(..) is called after mysql_real_connect(..) which has no effect on the connection. Mysql_options must be called before mysql_real_connect(..).

Making these two changes in my environment seemed to have resolved the problem as the same test case I have no longer fails.

=======================

stacktrace

/opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/adapters/data_objects_adapter.rb:92:in execute_non_query': (mysql_errno=2006, sql_state=HY000) MySQL server has gone away (MysqlError) Query: Mysql server has gone away. Please report this issue to the Datamapper project. Specify your at least your MySQL version when filing a ticket<br/>

from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/adapters/data_objects_adapter.rb:92:in `execute'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/adapters/data_objects_adapter.rb:173:in `with_connection'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/adapters/data_objects_adapter.rb:90:in `execute'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/adapters/data_objects_adapter.rb:80:in `update'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/repository.rb:76:in `update'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/resource.rb:603:in `hookable__update_nan_before_advised'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:299:in `update'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:297:in `catch'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:297:in `update'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/resource.rb:295:in `hookable__save_nan_before_advised'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:299:in `save'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:297:in `catch'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.12/lib/extlib/hook.rb:297:in `save'
from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/resource.rb:538:in `update_attributes'
from /opt/local/anr-0.2.0/lib/report.rb:85:in `finished'

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 2nd, 2009 @ 01:27 AM

    • State changed from “new” to “unconfirmed”
    • Assigned user set to “Dirkjan Bussink”
  • Dirkjan Bussink

    Dirkjan Bussink July 2nd, 2009 @ 01:36 AM

    • State changed from “unconfirmed” to “resolved”

    This is already fixed in the next branch, which will be released as 0.10 in the near future. You can already get a beta gem from gems.datamapper.org

  • Phillip Liu

    Phillip Liu July 2nd, 2009 @ 11:50 AM

    Using 0.10.0 from gems.datamapper.org, I still get the following stacktrace. Looking at 0.10.0 version of do_mysql_ext.c, it seems the problems I stated above is still there.

    ====================== /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/adapters/data_objects_adapter.rb:159:in execute_non_query': MySQL server has gone away (DataObjects::SQLError)

    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/adapters/data_objects_adapter.rb:159:in `execute'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/adapters/data_objects_adapter.rb:263:in `with_connection'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/adapters/data_objects_adapter.rb:157:in `execute'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/adapters/data_objects_adapter.rb:131:in `update'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/repository.rb:165:in `update'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:328:in `update!'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:717:in `hookable___update_nan_before_advised'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/hook.rb:299:in `_update'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/hook.rb:297:in `catch'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/hook.rb:297:in `_update'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:304:in `update'
    from /opt/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:42:in `update_attributes'
    from /opt/local/anr-0.2.0/lib/report.rb:85:in `finished'
    
  • Phillip Liu

    Phillip Liu July 2nd, 2009 @ 11:52 AM

    • Tag changed from 0.9.12, do_mysql, reconnect to 0.10.0, 0.9.12, do_mysql, reconnect
  • Dirkjan Bussink

    Dirkjan Bussink July 2nd, 2009 @ 03:05 PM

    Could you check with the latest code from the next branch? I probably added it after the beta gems were released then.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Pages