简体   繁体   English

Couchbase Java客户端IllegalReferenceCountException

[英]Couchbase java-client IllegalReferenceCountException

I was getting this error on java-client-2.1.0 while trying to work with AsyncBucket : 尝试使用AsyncBucket我在java-client-2.1.0上收到此错误:

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. Couchbase完全忽略了这种情况,因此库没有适当的反馈,而Netty内部人员也无济于事。

Turns out you'll get that error when consuming CB's items more than once. 原来,当您多次消费CB的物品时,您会得到该错误。 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() : 要解决此问题,请使用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. 缓存观察者将使用Couchbase的项目,然后多个订阅者可以安全地从缓存中使用。

If you're using rxscala , the fix is the same. 如果使用rxscala ,则修复方法相同。

getObs.singleOption.foreach { ... }

Would fail without the cache. 没有缓存将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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