Hello all,
I have recently come across an issue where if I try and store some values into CB i get the following error:

“description”: “java.lang.IllegalStateException: The content of this Observable (querySignature.09b27ec9-3ac6-4173-b5ef-2975c0b93fa6) is already released. Subscribe earlier or tune the CouchbaseEnvironment#autoreleaseAfter() setting.: \tat com.couchbase.client.core.utils.UnicastAutoReleaseSubject$”, “bindingResult”: “Unexpected exception occurred.”

The thing is it doesnt always happen, its random and I cant determine how/why/when. I read this post JAVA Client:IllegalStateException but as im new to CB and a junior it doesnt really say much to me. Any further help/suggestions/tips are highly appreciated on how to go forward with this issue.

Okay so I managed to find where the issue is happening and why but cant figure out a solution, in my code I have the following:

Observable.from(items).flatMap((t) -> { code logic }).last().toBlocking().single();

Im assuming that during the "code logic " part there is a lot of computation which takes a while and so the error is thrown. I tried using .autoreleaseAfter() but it does not recognise that. Any ideas?

Hi @CouchPatata

With reactive programming it’s crucial that any code inside operators, e.g. your “code logic” block there, has to be be non-blocking. Are you doing anything like making blocking network calls or the like? Perhaps you could give a more complete snippet, or even a minimally reproducible project, for us to take a look at?

The basic problem is that by the time you get to the subscription (will be somewhere in the last().toBlocking().single() part), the Observable created inside the Java SDK has already been released. This is a safety measure to prevent resource leaks due to application’s not subscribing to the Observable. So, something’s taking too long.