0

I have the Following CouchBase Template Bean:

 @PostConstruct
public void initIt() throws Exception {
    if(couchbaseDisabled)
        return;
    couchbaseClient= new CouchbaseClient(
            bootstrapUris(Arrays.asList(hosts.split(","))),
            CouchbaseConstants.BUCKET,
            ""
    );
    couchbaseTemplate();
}



public void couchbaseTemplate() throws Exception {
    logger.info("Enabling CouchBase Template");
    couchbaseTemplate= new CouchbaseTemplate(couchbaseClient);
    //couchbaseTemplate.
}

and

@PreDestroy
public void cleanup() throws Exception {
    logger.info("Closing couchbase connection.");
    if (couchbaseClient != null) {
        couchbaseClient.shutdown();
        couchbaseTemplate=null;
        couchbaseClient=null;
    }
}

While the Server is being Shut Down i am geting the Following Logs:

SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@5ddaa15d]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@3c9810ce]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@23776376]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@7322ea2a]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:32 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8099

What can be Done Here?

Simon Baslé
  • 27,105
  • 5
  • 69
  • 70
  • can you confirm which versions of Spring Data Couchbase and the Couchbase SDK you are using? I'm under the impression you have `SDC 1.4.x` and also direct reference to a SDK `2.x.y` in your pom.xml. – Simon Baslé Jan 08 '16 at 12:52
  • note that these warnings from Tomcat could be ignored if you always plan on fully stopping/restarting the server, as opposed to hot redeploys. – Simon Baslé Jan 08 '16 at 12:54
  • Its : org.springframework.data spring-data-couchbase 1.0.0.RELEASE – Ishan Malhotra Jan 08 '16 at 12:56
  • wow that's quite an old one... what I find strange is the mention of `com.couchbase.client.deps.io.netty.util.internal` in the logs, are you sure you don't have a dependency on `com.couchbase.client`:`java-client`, even as a transitive dependency somewhere? (you could probably see it eg. in the External Dependencies listing of your IDE) – Simon Baslé Jan 08 '16 at 13:08
  • i am implementing the Template for the first time, Just now moved to 1.4.2.RELEASE. Will revert if i face any issue. OPen to other Suggestion – Ishan Malhotra Jan 08 '16 at 13:37
  • have a look at the docs, usually you shouldn't have to build the template bean, just extend `AbstractCouchbaseConfiguration` and provide the few elements of configuration (bucket name, URLs, bucket password) that are needed – Simon Baslé Jan 08 '16 at 13:40
  • This also coming for 1.4.2. Also in my POM this also Exists com.couchbase.client java-client – Ishan Malhotra Jan 08 '16 at 13:45
  • I did that to meet some requirments! – Ishan Malhotra Jan 08 '16 at 13:46

1 Answers1

0

Ok so you have both SDK 1.4.x and 2.x running in your application (since you have com.couchbase.client:java-client in your pom).

The thread leak message comes from the later. You must have instantiated a Cluster somewhere (as in com.couchbase.client.java.Cluster). Make sure to also clean it up at the end of the application's lifecycle by calling cluster.disconnect() (I guess from a @PreDestroy method, as you did for the CouchbaseClient).

If you also created a custom CouchbaseEnvironment, you have to also properly shut it down (in the same method as the Cluster cleanup) by calling environment.shutdownAsync().toBlocking().single().

Make sure to use the latest version of the 2.x SDK as some older versions had bugs relative to proper thread cleanup on shutdown (see JCBC-773 and JVMCBC-251 issues).

Simon Baslé
  • 27,105
  • 5
  • 69
  • 70