Couchbase timeout prematurally

Hi,
I have two threads. The main thread receives requests through http service. For each request, a key in couchbase needs to be updated accordingly. The update operation is done in the second thread, which owns a couchbase client backed up by libev and drives the event loop manually (by calling ev_run on the loop). Each time an request is arrived, the main thread puts the key in a locked queue and notify the second thread by calling ev_asyc_send on an ev_async object watched by the second thread.
In the callback of the ev_async event, the second thread pull out all keys currently in the locked queue and send get commands to couchbase for them. After the value of a key is gotten, the value is modified and a store command is sent to couchbase for it.
The problem is, sometimes the actual operation timeout value is much less than the value I set by calling lcb_set_timeout. For example, if I set a timeout value of 10ms, some request timed out only 1 or 2 ms after lcb_get is called. But this phenomenon is never observed if I update couchbase value in the main thread (for each request, send get command to couchbase directly in the main thread and call lcb_wait until the value is gotten).
Has any body meet the same problem under this scenario?
Any comment or help is appreciated, thanks in advance!

This is a known bug which should be fixed in the upcoming release.

If driving the event loop manually, you should be calling ‘lcb_wait()’ if you desire prompt termination of the loop when all pending operations have completed.

Currently, the timeout is set from the moment that the command is scheduled, not when the event loop is invoked. The lcb_wait() function will readjust the timeouts to the current time, whereas just letting the event loop run manually (i.e. ev_run) will not.

Depending on how you’re queueing operations, this may also be a factor.

Thanks for the reply!

we have viewed the first problem (event loop won’t quit after all pending operations have completed) and find some workaround(call lcb_wait in the event handler and then call ev_break).

For the timeout issue, we computed the time distance from the moment we call lcb_get to the moment our callback is called, it is still much less than the timeout value set by us.