Fetching from couchbase during deserialization

In my application I am trying to migrate to couchbase based caching. I have complex java objects where a single object is referenced from many objects. Now this single object as well as the complex java object needs to be stored in the cache. I am storing the java object in the form of SerializedDocument in couchbase into a single bucket.
I have implemented custom deserialization in my code. If some object is already put into cache(say A) and this object needs to be serialized again as a member of another object (say B) then I am replacing this object with a proxy class object (PrimaryKeyWrapper) using writeReplace of java.

Now when B is fetched from the bucket:
In class PrimaryKeyWrapper I have implemented readResolve where I am fetching the object stored in couchbase with this primary key.

Now at this point my application fails or gets stuck(depending on the bucket.get timeout) 1 out of 10 times. After the bucket fetch timeout is passed I get below exception:

Exception in thread “main” java.lang.RuntimeException: java.util.concurrent.TimeoutException: {“t”:2500000,“b”:“cache”,“s”:“kv”,“r”:“”,“c”:“3568346A5BD3C670/FFFFFFFF98641C61”,“l”:“0:0:0:0:0:0:0:0:57380”,“i”:“0x4”}

  • at rx.exceptions.Exceptions.propagate(Exceptions.java:57)*
  • at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:463)*
  • at rx.observables.BlockingObservable.singleOrDefault(BlockingObservable.java:372)*
  • at com.couchbase.client.java.CouchbaseBucket.get(CouchbaseBucket.java:149)*
  • at com.couchbase.client.java.CouchbaseBucket.get(CouchbaseBucket.java:144)*
  • at CouchbaseCacheProviderImpl.get(CouchbaseCacheProviderImpl.java:46)*
  • at MainClass.serializableTest(MainClass.java:21)*
  • at MainClass.main(MainClass.java:5)*
    Caused by: java.util.concurrent.TimeoutException: {“t”:2500000,“b”:“cache”,“s”:“kv”,“r”:“”,“c”:“3568346A5BD3C670/FFFFFFFF98641C61”,“l”:“0:0:0:0:0:0:0:0:57380”,“i”:“0x4”}
  • at com.couchbase.client.java.bucket.api.Utils$1.call(Utils.java:131)*
  • at com.couchbase.client.java.bucket.api.Utils$1.call(Utils.java:127)*
  • at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)*
  • at rx.internal.operators.OnSubscribeTimeoutTimedWithFallback$TimeoutMainSubscriber.onTimeout(OnSubscribeTimeoutTimedWithFallback.java:166)*
  • at rx.internal.operators.OnSubscribeTimeoutTimedWithFallback$TimeoutMainSubscriber$TimeoutTask.call(OnSubscribeTimeoutTimedWithFallback.java:191)*
  • at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)*
  • at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)*
  • at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)*
  • at java.util.concurrent.FutureTask.run(FutureTask.java:166)*
  • at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)*
  • at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)*
  • at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)*
  • at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)*
  • at java.lang.Thread.run(Thread.java:722)*
    Apr 17, 2019 12:26:10 PM com.couchbase.client.java.transcoder.AbstractTranscoder decode
    WARNING: Decoding of document with SerializableTranscoder failed. exception: java.util.concurrent.TimeoutException: {“t”:2500000,“b”:“cache”,“s”:“kv”,“r”:“”,“c”:“3568346A5BD3C670/FFFFFFFFE73666BA”,“l”:“0:0:0:0:0:0:0:0:57381”,“i”:“0x5”}, id: “test-cache::b”, cas: 1555484168023244800, expiry: 0, flags: 0x1000001, status: SUCCESS, content size: 282 bytes, content: "??

The attachment contains the the source files of my application and the thread dump of my application before the timeout exception occurs.

PS: I cannot store the object as JSON as in my actual application the objects to stored in the cache are generated by a different framework on which I have no control.attachment.zip (6.5 KB)

couchbase client version - 2.7.3
couchbase server version - 5.0.1

I have found a similar topic -

The user here is facing this issue when the object graph level becomes 3 or more, I am facing this issue with just a single level of object graph

Hi @vyomt,

I’m inviting @deniswsrosa to check this out. He is traveling this week, but I know he’s been working on a caching library recently, so he might be able to help you.