4

After using a bit of the java client API of Couchbase (2.4.1) I ran into this exception:

Error in scheduled task java.lang.IllegalStateException: 
The Content of this Observable is already released. 
Subscribe earlier or tune the CouchbaseEnvironment#autoreleaseAfter() setting.

I was using a ViewQuery in imperative mode, it fails when getting the rows from the result (ViewResult is correct as totalRows() and success() have nice values)

ViewResult result = service.executeViewQuery(...);
List<ViewRow> rows = result.allRows();

Effectively setting up autoreleaseAfter solves the problem but I don't know if it is safe or just side-stepping the problem.

CouchbaseEnvironment env = DefaultCouchbaseEnvironment
            .builder()
            .autoreleaseAfter(5000)
            .build();

I guess this mode doesn't close the connection after a query, it lets it live until the timeout (5 seconds) is achieved.

Does it close automatically "earlier" if the http call is finished (using Spring MVC)? It seems that mode brings danger as it can hold more connections but does it really matter?

Finally I feel that the "correct" use of this API is to go through rxjava Observable API whereas most of the documentation found only show imperative examples. Is autorelease mode out of date (and going to become deprecated) or is it still going to be supported in near future?

zenbeni
  • 7,019
  • 3
  • 29
  • 60
  • hey benjamin :) could it be that more than 2s (default autorelease timeout) elapse between your code calling `executeViewQuery` and the part where `result.allRows()` gets called? – Simon Baslé Jan 31 '17 at 18:37
  • @SimonBaslé hey pal! :) Actually the query is very fast and computation between services shouldn't take more than 2 seconds. Moving all my code into just one Spring service solves this problem (the service does the query and the parsing) and I don't need an increased timeout anymore. Maybe calling all methods ViewResult.debug(), ViewResult.totalRows(), ViewResult.error(), ViewResult.success() into another service after client.query(...) causes this behaviour (closing the connection early), I don't know. – zenbeni Feb 01 '17 at 09:02

2 Answers2

4

While researching this topic I found another case here where a similar bug appeared in Couchbase.

By default autoReleaseAfter() is set to 2000 ms. I guess that the default time window is not long enough for your subscriber to subscribe to the Observable which causes the Content of your Observable to be autoreleased to prevent a leak. Setting it to 5000 ms manually is long enough in your case. Unfortunately I do not know whether it has any side effects.

I am pretty sure that autoReleaseAfter() will not deprecate soon. If this was the case it would be noted in the Couchbase source or in the docs (at the end of the page, search for "Automatic Observable Resource Release Time Period").

I think you should report this bug to the Couchbase devs.

Robin Ellerkmann
  • 2,083
  • 4
  • 29
  • 34
1

The "autoreleaseAfter" option in the Couchbase Environment specifies the amount of time (in ms) after which the environment will automatically release memory that it has allocated. This can help to prevent memory leaks in applications that use the Couchbase Environment.