N1QL Query: With adhoc=false query runs into IllegalStateException: The content of this Observable is already released

When I run a query with a large resultset (60k documents for some kind of export) I am getting an error like this:

Error: java.lang.IllegalStateException: The content of this Observable (queryRow. / 0169c97b-99da-4ff0-90f1-569dfd5b08e1) is already released. Subscribe earlier or tune the CouchbaseEnvironment#autoreleaseAfter() setting.

This is how I execute the query with adhoc=false:
N1qlQuery q = N1qlQuery.parameterized(queryString, params, N1qlParams.build().pretty(false).adhoc(false));

But:
When I switch adhoc=true then everything is fine and I do not get this error.

Couchbase Sever Version: “4.6.0-3453-enterprise”
Java SDK: v2.3.5

Any hints on why this happens and what I can do to use adhoc=false and use prepared statements?

@synesty thanks for the question. I’m going to tag @subhashni as she might be able to help. Also, this question maybe belongs in the Java forum: https://www.couchbase.com/forums/c/java-sdk

Thanks. I moved the question to the Java SDK Forum.

Hi @synesty, It happens if there wasn’t a subscription, but for blocking sync api we should be consuming as the response comes in. Lets try this, can you increase autoreleaseAfter timeout using environment builder, it is 2 seconds by default and see if it helps

CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().autoreleaseAfter(5000).build()
1 Like

Thanks @subhashni I will try that. But what is the reason that it depends on the adhoc parameter?

It is not specific to adhoc. Adhoc as false uses a different path to query as it is prepared, sdk would prepare and cache the query plans and execute the query with the plan. All the query response observables have auto release timeout set. It is possible that in your case, observables during prepare phase run into timeouts. It should not happen per se if there weren’t delays in consuming the response, so let’s see if increasing the timeout fixes it, else debug/trace logs may help diagnose it.

autoReleaseAfter=50000 has helped. 5000 was too small, probably because the query takes longer.

env = DefaultCouchbaseEnvironment
        .builder()
        // autoReleaseAfter is to avoid "The content of this Observable is already released." errors
        // see https://www.couchbase.com/forums/t/n1ql-query-with-adhoc-false-query-runs-into-illegalstateexception-the-content-of-this-observable-is-already-released/11004/4?u=synesty
        .autoreleaseAfter(50000)
        .retryStrategy(FailFastRetryStrategy.INSTANCE)
        .reconnectDelay(Delay.fixed(retryintervalsec, TimeUnit.SECONDS))
        .build();

@synesty to help collect some data points, would it be possible for you to run PREPARE via cbq/ui and see how long it takes?

How long does the query itself take to complete?

@daschl

Prepare:

PREPARE select meta(datastoreitems).id, * from datastoreitems WHERE datastore_id = $datastoreId LIMIT 2147483647

Elapsed: 8.20ms Execution: 8.14ms Result Count: 1 Result Size: 5509

Query itself:

N1qlMetrics{resultCount=65869, errorCount=0, warningCount=0, mutationCount=0, sortCount=0, resultSize=65757131, elapsedTime='8.505336496s', executionTime='8.505275995s'}

Thanks @synesty. This looks like a bug, I’ve filed a ticket JCBC-1029.

1 Like