简体   繁体   中英

Couchbase java-client IllegalReferenceCountException

I was getting this error on java-client-2.1.0 while trying to work with AsyncBucket :

com.couchbase.client.deps.io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1

After a while I figured it out. Couchbase completely ignores this scenario so there's no proper feedback from the library and the Netty internals aren't helping.

Turns out you'll get that error when consuming CB's items more than once. For example,

val getObs = asyncBucket.get("blah")
val emptyObs = getObs.isEmpty.doOnEach(...).subscribe()
val docObs = getObs.doOnEach(...).subscribe()

That is the only way I could come up with to handle a "document not found" scenario.

To work around this, use cache() :

val getObs = asyncBucket.get("blah").cache()

The caching observer will consume the Couchbase's item and then the multiple subscribers can safely consume from the cache.

If you're using rxscala , the fix is the same.

getObs.singleOption.foreach { ... }

Would fail without the cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM