Connection error when running memcached with dalli - ruby

I'm having trouble connecting to a Memcached server running on localhost from Dalli. I have been using Dalli with the Memcachier Heroku add-on for a while without any problems though I don't have any experience running Memcached locally.
I downloaded memcached with homebrew and it seems to have installed without a problem. I'm running it like this:
memcached -l 127.0.0.1 -p 11211 -vv
I can connect to the server and query it with
telnet 127.0.0.1 11211
The verbose output of memcached logs all the requests, so I know it's running fine. However, I'm unable to run it with Dalli. I am trying to connect like this:
require 'dalli'
dc = Dalli::Client.new('127.0.0.1:11211')
dc.set('foo', 123)
After I run the last command, Dalli unfailingly spits out
Dalli::RingError: No server available
from /Users/mac/.rvm/gems/ruby-1.9.3-p392/gems/dalli-2.6.4/lib/dalli/ring.rb:45:in `server_for_key'
from /Users/mac/.rvm/gems/ruby-1.9.3-p392/gems/dalli-2.6.4/lib/dalli/client.rb:347:in `perform'
from /Users/mac/.rvm/gems/ruby-1.9.3-p392/gems/dalli-2.6.4/lib/dalli/client.rb:199:in `set'
... so I'm getting this connection error, but I don't know why. Here's the weird part: Memcached is receiving the request, but it never succeeds in connecting. The following two lines are spit out by the verbose output whenever I try to connect:
<6 new client connection
<6 connection closed.
So what's going on here? Is this an authentication thing? Am I forgetting a command-line option?
EDIT: Figured out what was going on -- I was doing everything right except I was using the builtin version of Memcached. Installed the latest version and everything was fine.

Pretty simple issue, actually: I was just using an out-of-date Memcached version. No idea why that breaks Dalli, but installing a new Memcached fixed it.

That breaks dalli because dalli uses the newer binary memcached protocol instead of the older text-only protocol.
It does this for performance, but unfortunately makes dalli unusable with versions older than memcached 1.4

Related

rails s doesn't start server, no error messages

I haven't been able to find previous answered questions on this, unless I'm missing one. Anyways, when I try starting a rails server:
vagrant [accounts]> rails s
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-06-06 02:38:50] INFO WEBrick 1.3.1
[2015-06-06 02:38:50] INFO ruby 2.2.2 (2015-04-13) [i686-linux]
[2015-06-06 02:38:50] INFO WEBrick::HTTPServer#start: pid=23016 port=3000
But that's all I ever get, no error messages or anything. Of course localhost:3000 produces 'no data received'
As you can see I'm using Ruby 2.2.2 and Rails 4.2.1
I'm in the root for the app, have tried updating bin.
I'm using the sqlite3 gem, I've created and migrated the db.
I am convinced it has nothing to do with this particular rails app because I've gone back and tried to open old projects that are now having the same problem. Recently I've upgraded from Ubuntu 12.04 to 14.04 on my vm. I've also recently upgraded ruby (I manage with rvm) and rails. I've also recently put some stuff on heroku. All of this has messed with $PATH (I'm not sure if this is related, I'm pretty new to all this stuff). Just wanted to detail everything I could think of that might have an effect.
Thanks!
I ran into the following problem recently, could this be your issue also?
If so try
rails s -b 0.0.0.0
3.3 Default Host for rails server Due to a change in Rack, rails server now listens on localhost instead of 0.0.0.0 by default. This
should have minimal impact on the standard development workflow as
both http://127.0.0.1:3000 and http://localhost:3000 will continue to
work as before on your own machine.
However, with this change you will no longer be able to access the
Rails server from a different machine, for example if your development
environment is in a virtual machine and you would like to access it
from the host machine. In such cases, please start the server with
rails server -b 0.0.0.0 to restore the old behavior.
If you do this, be sure to configure your firewall properly such that
only trusted machines on your network can access your development
server.
See the release notes here for the details.

While I try install 'gem install watir' I get this error

While I try to install the watir, I have the following error, Can anyone please guide me how to resolve this problem?
C:\>gem install watir -v 4.0.2
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNRESET: An existing connection was forcibly closed by the remote
host. - SSL_connect (https://api.rubygems.org/api/v1/dependencies?gems=watir-webdriver)
I am using Ruby 2.1.5 and WATIR 4.0.2.
Whenever you see the following error:
Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.
But you can access internet normally, it has a high possibility that your request has been blocked by the Chinese governments' Great Firewall.
In such case, you can try changing your DNS settings to 8.8.8.8(Google) if you are not in China, or you can use Taobao's mirror otherwise.
See ruby.taobao.org for details, if you understand Chinese.
The worst case is that the IP of the server serving the gem is blocked by Great Firewall. It will intercept TCP handshakes by send RST packets to both your browser/client and the server. In such case, you have to use some proxy or VPN to get your job done.
You need to change your rails ssl certificate

i cannot install haml using "gem install haml"

i have already downloaded ruby 2.2.1 and in command prompt i hv tried the command
gem install haml
but error is coming like:
ERROR: Could not find a valid gem 'haml' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - Errno::ECONNREFUS ED: No connection could be made because the target
machine actively refused it.
- connect(2) for "api.rubygems.org" port 443 (https://api.rubygems.org/specs.4.8 .gz)
It might be because of the firewall company have put up in every system. I have gone through trying different proxies picked up from different websites. Can anybody tell how to install or use haml/sass?
Company firewalls, the bane of many a developer's existence.
The best thing you can do:
Talk to the local networking team and get it unblocked for direct access.
If that fails:
Do they have a proxy you can use? gem will honor proxy variables, so if you get access to one, you can do an export https_proxy="http://someaddress:someport", and then your command should work.
If that also fails
Now we're left with circumventing the network policies - Be careful, as this could get you in trouble.
Options include:
Getting an external proxy that allows port 80 (it sounds like 80 works from your question). You could set up a squid instance on your home machine and access it that way via the variable method above.
Doing an SSH tunnel through a machine that does have unrestricted internet access, and using tsocks to tunnel through there.
There are others, but these two are relatively easy to set up.
I must emphasize here, be careful! Even if your networking group is impeding your ability to do your job, either get your boss's support, or be as stealthy as possible and discontinue use of these tools once you have what you need.
If it's a rails project, you can try to change the first line of your Gemfile from source 'https://rubygems.org' to source 'http://rubygems.org'.
If you are using a ruby project, try to download gem without https, like : gem install -s http://rubygems.org haml

How to close MySQL connection & quit program immediately in Ruby?

Here's my program.
require "mysql"
db = Mysql.new("127.0.0.1", "root", "some password", "test")
db.close
db = nil
When I run this program, it doesn't finishes. I need to send Ctrl+C to stop execution.
How can I make this program close the connection and quit immediately and gracefully? (Ruby 2.0.0)
Update
I discovered new symptom. It hangs instead of quit and seems like running an infinite loop. Because my CPU monitor told me it is using 100% of one core. I am not still sure this is Ruby issue or MySQL library issue or my configuration issue...
Your script is fine.
In your specific case, it doesn't quit because the client times out when conecting to the server at the given IP 10.211.55.10. It never even gets to db.close.
I've reproduced this locally. I changed the code to connect to my local MySQL and the script quits immediately.
I can reproduce the same hanging when I manually connect with the client:
$ mysql -u root -p -h 10.211.55.10
Enter password: [masked]
ERROR 2003 (HY000): Can't connect to MySQL server on '10.211.55.10' (60)
The error message appears after timing out. Are the credentials correct? Does the server accept connections?
I finally figured out workaround.
I have installed all brew, rvm, ruby almost 10 times to figure out where the problem is.
It was because of bad MySQL connector C library.
I installed the connector with Homebrew,
brew install mysql-connector-c
and used wrapper version of ruby gem.
gem install mysql
Anyway I tried pure-ruby based version and it doesn't hang. works well.
brew remove mysql-connector-c
gem uninstall mysql
gem cleanup all
gem install ruby-mysql
# Now everything working well without hanging at last.
Anyway, mysql-connector-c package and mysql gem works fine on Ubuntu Linux. (I am using OS X)
So the core problem was OS X version of C connector installed by brew.
This could be a little bit slower, but it doesn't matter on dev machine, because final distribution will be based on Linux.

Cannot access Heroku postgres from CLI, SSL support issue

I'm having trouble connecting to my Postgres database on Heroku.
I run heroku pg:psql from the terminal, and get the error:
psql: sslmode value "require" invalid when SSL support is not compiled in
All the instances I find of this error online are php related, and it's only started acting up recently. Anybody know what's up with this?
Your local psql binary was not compiled with SSL support. You will need to locally recompile (or otherwise acquire for your os a binary of) postgres with SSL.

Resources