New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using rails connect hangs when initialized from script/server, but not from script/console #51
Comments
What version of ruby (also - 32bit/64bit?), which webserver are you using? |
Any possibility of a smaller reproducible test-case? I'm unable to replicate the issue. |
I will try to create a sample rails app with the minimum code that can reproduce the problem. I think I mentioned that only the connection to some servers stall, connecting to other servers works ok. The surprising element is that the troublesome servers work perfectly from script/console AND when using the older mysql gem. Also it may be relevant that the app that is having the issue has a about 10 mysql connections to other servers (it's a sharded app, lots of databases, etc.) already stablished when the problem occurs. Don't know if we may be finding some global maximum (will do some tests). Thanks for your help, |
Hi, This is the simplest test case I could create. SETUP:
BEHAVIOUR: webrick fails:
mongrel_rails fails:
script/console works ok:
In order to reproduce the bug we need: webrick + mysql2 + connection to a certain server mysql2 can connect to other mysql servers without any problem, using mysql gem solves the problem, running the code from script/console solves the problem This is the info of one target mysql servers that work well: And this is two servers that do not Server version: 5.1.47-rel11.0-log (Percona Server (GPL), 11.0 , Revision 47) so it doesn't seem related to a certain mysql version. I don't have any idea at all of what could be happening here... |
could a network sniffer help in any way? |
A recent patch fixed a long standing bug that was probably the culprit of all of the strange hard to reproduce (for me) bugs people have been seeing. Would you mind giving master a try? |
sure! will get back to you tomorrow |
Sorry for the delay. Unfortunately the problem persists. |
I'm experiencing the exact same problem with rails 2.3.5+ and the latest source (updated as of the last commit). It simply hangs on boot every time with webrick, thin, mongrel, etc. |
Same thing here. $ rails -v |
Also, the problem persists with ubuntu 10.04, both 32-bit and 64-bit, though it occasionally starts and finishes loading webrick on the 64-bit once in a blue moon. I usually have to restart the AWS instance to get it to do that again, however. |
Could you recreate me a small sample Rails application that reproduces the issue for you? Unfortunately there's nothing I can do until I can reproduce it on my end as well. |
Or if you guys don't mind giving me temporary access to a server that has this issue (and has some debugging tools installed) that would be awesome as well |
Hi Brian, I believe the problem must be associated to our specific environment, I actually was able to reproduce it in app that was created from scratch (see Sep 3th message) I'll try to arrange an ssh access to a server where you can see the problem live. Thanks for your help! |
Hi Brian, While on the process of setting up the server to do the test you requested, I have found that the issue could be related to network latency. The problem cannot be reproduced when I connect to a server from a machine in the same datacenter, but happens always when I connect:
I have also verified that the problem occurs both when the client is running Mac OS X and Ubuntu 9.10 (karmic). Can you send me (angel{at}vlex.com) your IP and I'll set-up the firewall permissions so you can test this from your own machine? Thanks! |
Brian, I'll set up a test server right now and send you a message with contact details & an ssh key (its going to be on aws) for you to access it. |
Awesome thank you! |
Following John@AWS's recommendation (http://developer.amazonwebservices.com/connect/thread.jspa?messageID=153250𥚢), I set character_set_server=utf8 and collation_server=utf8_general_ci. Still no luck. I also tried upgrading to 0.2.6. |
This appears to be something environment specific. I am not able to connect to my staging server from my machine with mysql2. However, I am able to connect to my staging server from Heroku with mysql2. In both cases I am using the same webapp. |
I am now able to connect to my mysql server with mysql2. However, my co-worker cannot. I have no idea what differences there are between our two machines. |
What do your database.yml files look like? |
|
We discovered that once we installed RVM (http://rvm.beginrescueend.com/), this problem went away. |
That's definitely interesting... Are you guys still having issues on Ubuntu as well? |
Ubuntu was another team. |
Could you try setting a connect_timeout in database.yml to something very low? |
I'm experiencing the same problem with rails3.0.4 on Windows7, Is there a known solution for this issue? (OSX and rails3.0.4 works just fine) |
Could you guys give this another try with 0.2.7? |
I'm in same hang-up too (with rails3.0.6 on Windows7). Even if I set wait_timeout or connect_timeout. Then I try to connect manually in Rails console,
It's okay until above, but
is hanged, And stack-traces are shown when Ctrl+C, and it indicates "mysql2-0.2.7/lib/active_reco |
Hi all, This issue is turning out to be a nightmare for many users including me. 'rake' task and rails server hanging with mysql2. Thanks |
I'm having issues with mysql2 hanging indefinitely as well. Hard to tell why or what's causing it. Using unicorn and sending an ActiveRecord::Base.establish_connection after forking. |
We just dealt with this same maddening issue on one of our projects, and found HTTPClient to be the culprit, specifically its custom implementation of Timeout. The Ruby process hangs as libmysqlclient.so attempts to establish a connection over the network. Attaching strace revealed an infinite loop of 20 system calls:
SIGVTALRM is used by Ruby to emulate threading, interrupting the current "thread" using an interval timer. EINTR is returned from the signal handler, and MySQL (or the mysql2 gem, I haven't investigated) responds by aborting and retrying connect(). We looked through our gems and found HTTPClient uses threads in a custom implementation of Timeout.timeout. Sure enough, we stopped loading the library, and the hang vanished. I don't have the time now to familiarize myself with the differences between HTTPClient's timeout.rb and the core implementation and discover where the bug lies. Is mysql2 or ActiveRecord doing something with threads or timeouts that might have similar effects? Our environment: Ubuntu 10.04 LTS |
I am having a similar problem. If I create a virtual machine in VirtualBox with Ubuntu 11.04, install rails 3.0.7 and mysql2 0.2.7, create an empty application with an empty model and controller, modify Gemfile to add mysql2, modify database.yml to point a remote mysql database, then run 'rails server', it will hang on the first access of the controller. I have tried both 64bit and 32bit. I am using ruby 1.8.7. |
Would you give 0.2.10 a try? |
Just tried 0.2.10. The problem still occurs. There appears to be a specific problem with the ruby package that is built for ubuntu. If I build it myself (1.8.7 p302) or use rvm (which does the same thing) the problem goes away. |
What's the version of Ruby that ships with ubuntu that you're having an issue with? |
For me (MariaDB on Windows), gem installation itself is failed after 0.2.9. Until 0.2.8, gem installation is succeeded. |
1.8.7 p302, I believe. A basic installation of Ubuntu 11.04 (for example, but I get the problem with older Ubuntus), run 'apt-get install ruby rubygems ruby-devel' will give you the problem. |
For me (MariaDB on Windows), both gem installation and rails execution go successfully in version 0.2.11 ! |
Here's another datapoint. I'm access mysql and mongo locally and tried adding a remote mysql connection today and ran into the problems described above ('rails console' works, 'rails server' hangs) on ubuntu 11.04. I switched to serving with thin, and the problem went away. I noticed that bundle grabbed 'eventmachine' during the install. Tried mongrel--it hangs too. |
closing due to inactivity. please reopen if you're still having trouble on the latest gems |
I second johnkolen's datapoint. I just tried starting up a fresh app connecting to a remote mysql database and was experiencing the very same hanging behavior described throughout the thread. Switching from WEBrick to thin seemingly has bypassed the issue. FYI, I'm running on OSX (Lion) with the prepackaged ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0], Rails 3.2.8, and mysql2 0.3.11 (also had same issues with 0.3.12b4). |
Hi,
A certain action in a rails 2.3.5 app stalls when using the mysql2 gem, after investigation we have narrowed this to mysql2 establishing the connection. The loop is on client.c in the function nogvl_connect. When stalled, the script/server process cannot be interrupted and only a kill -KILL will stop it.
The same connection arguments work just fine if the connection is established from script/console (or from a stand-alone ruby process, if that matters). Also the old mysql gem works fine from rails, and the mysql native client can connect perfectly to the server.
To make it clearer, this code hangs forever:
but this works perfectly:
This has been replicated in two machines (Mac OS X, Snow Leopard, 64 bits). The target server is
What information can we provide for a useful bug report? We have the C and ruby call stack but that doesn't seem very useful.
The text was updated successfully, but these errors were encountered: