roc230 / spymemcached

Automatically exported from code.google.com/p/spymemcached
0 stars 0 forks source link

IOExceptions swallowed during connect #101

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Using 2.4.1 on Ubuntu 9.0.4 against memcached 1.2.8.

I appreciate the reconnect stuff, but I want to catch a failure to connect
at startup.  I have tried:
- catching IOException (doesn't come through)
- setting a negative reconnect delay (reconnect attempts just go faster)
- implemented my own ConnectionFactory and my own createConnection method
(no exceptions thrown)
- setting up my own initial observers (methods never get called)

What I've had to do at this point is just call getUnavailableServers()
right after the MemcachedClient constructor call, and if there are any in
the list, then do a shutdown.

What I really want is ConnectionFactory.setRetryAttempts(int num), so that
I can control how many times it tries.  I want to fire off an alert to
operations when that happens.

I keep thinking there has to be some obvious way that I just cannot spot...

Original issue reported on code.google.com by dwitherspoon3 on 30 Oct 2009 at 6:35

GoogleCodeExporter commented 9 years ago
You can do most of what you want with a connection observer.  I do that in the 
test
case for it here:

http://github.com/dustin/java-memcached-client/blob/master/src/test/java/net/spy
/memcached/ObserverTest.java#L28

It's a bit more complicated, but this allows you to do two things:

1. Send off alerts on the exact connects and disconnects you're interested in.
2. Use a latch to wait for connections to come up during initialization code 
and fail
if enough connections don't come up within enough time.

For example, if you were bringing up 100 connections, you might consider your
application successfully initialized at the point where 75 of them come up.  
With a
countdown latch counting down from 75, at the point where the latch releases, 
you're
good.  If you get a timeout before the latch releases, you'll get a timeout 
exception
and can decide to fail and shut down.

I'm going to mark this as invalid because I do think it's possible to do what 
you
want currently.

Original comment by dsalli...@gmail.com on 31 Oct 2009 at 7:58