5

I have deployed my web app inside a tomcat container but due to a possible connection leak , the web app is constantly making failed attempts to connect to the local memcached server listening at port 11211 and 11212. I am using the spy-memcached client.

I have a ContextListener defined which basically shuts down all active memcached client connections.

However when I un-deploy my web app , it appears to me that tomcat is still trying to continue with failed attempts to connect to the memcached server, which it should not.I have checked the active tcp connections on memcached server using netstat but I could not find any entry.

I have also restarted the tomcat server but to no avail as such.

How should I restrict tomcat from making these connections?

2011-11-13 21:21:34.575 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=localhost/127.0.0.1:11212, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:407)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:275)
    at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:2030)
2011-11-13 21:21:34.576 WARN net.spy.memcached.MemcachedConnection:  Closing, and reopening {QA sa=localhost/127.0.0.1:11212, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 32.
A Null Pointer
  • 2,261
  • 3
  • 26
  • 28
  • Are the reconnection attempts causing problems? Is it a problem that needs solving necessarily? – Jason Buberel Nov 13 '11 at 18:34
  • They are not causing any problems per se , but they are just dangling reconnects which bothers me as it fills up my entire log space. I somehow got to the point where I manually had to terminate all incoming connections out of port 8080 to port 11211 and 11212 and I think that has kind of worked out for me. But I still dont understand why would the stale connections persist even after the context is destroyed ?? – A Null Pointer Nov 13 '11 at 18:38
  • I'm having the same issue, environment is spymemcached 2.8.1, tomcat 6 on linux 2.6.18.2-34-default. MemcachedClient shutdown gets called in contextDestroyed of ServletContextListener. The weird thing is the error message is saying: 2012-06-28 11:00:39.753 INFO net.spy.memcached.MemcachedConnection: Reconnecting {QA sa=/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} But I've ever used port 11212 in my application, somehow it defaults to 11211... – dvd Jun 28 '12 at 18:16
  • I think this thread on spymemcached's group is describing the same issue. https://groups.google.com/d/topic/spymemcached/lMpHWENfKEE/discussion However setting daemon and calling shutdown doesn't help. – dvd Jun 28 '12 at 18:46

1 Answers1

1

I was facing the same problem.Setting daemon true works for me. I am using spymecached-2.8.4 I get the Memcached Client through net.spy.memcached.spring.MemcachedClientFactoryBean though Spring (spring - 3.1.1), here is my spring configuration that I use in my web applicaton :

<bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean">
        <property name="servers" value="localhost:11211"/>
        <property name="protocol" value="BINARY"/>

        <property name="transcoder">
            <bean class="net.spy.memcached.transcoders.SerializingTranscoder">
                <property name="compressionThreshold" value="1024"/>
            </bean>
        </property>

        <property name="opTimeout" value="1000"/>
        <property name="timeoutExceptionThreshold" value="1998"/>
        <property name="hashAlg">
            <value type="net.spy.memcached.DefaultHashAlgorithm">KETAMA_HASH</value>
        </property>
        <property name="locatorType" value="CONSISTENT"/>
        <property name="failureMode" value="Redistribute"/>
        <property name="useNagleAlgorithm" value="false"/>
        <property name="daemon" value="true"/>

    </bean>
Asraful Haque
  • 753
  • 8
  • 11