Calling queue pop in parallel return StatusKeyExists error

Hi,

I am using the latest Go sdk - v2.3.3
Server version: 6.6.3

I am using the Queue pop method like this:
err := v.bucket.DefaultCollection().Queue(someKey).Pop(&someValue)

When this is being called in parallel (I tested it using goroutines) it returns an error “StatusKeyExists”.
I did some deep digging and I saw that there’s a place where the SDK convert the “cas mismatch” error to a “document exists” (collection_subdoc.go, line 336), and because of that the pop function doesn’t retry the operation and simply returns the “document exists” error

Is this a bug in the SDK? or am I missing something?

I attached a screen shot of my SDK debugging…

Thanks,
Eli.

Screenshot 2021-10-24 at 12.20.18|360x500

Hi @Eli_gotesman I’ll confirm tomorrow but looking at this I suspect that you’re correct and we’re not matching the error correctly. If this is the case then I’ll get it fixed and in the next gocb release.

Hi @chvck ,
I updated the start of the post after some more deep digging
Thanks.

Hi @Eli_gotesman thanks for the detailed report, this is definitely a bug. I’ve raised [GOCBC-1185] Data structure operations looking for incorrect error - Couchbase database (and I’ve pushed a fix into our gerrit review system).

Thanks @chvck,

Do you have an estimation for the release?
We have this issue on our production and it causes some errors to our users, is there any walk-around we can do until the fix will be released?

Thank you.

@Eli_gotesman we release the Go SDK on the third Tuesday of each month so the next release is scheduled for November 16. I think that the only workaround would be to wrap your call into Pop with a loop and detect the document exists error - basically moving the error handling logic the SDK already does a layer up, e.g.

  err := myQueue.Pop(&myval)
  if err != nil {
    if errors.Is(err, gocb.ErrDocumentExists) {
      //  recurse or loop 
    }
    // handle the error
  }
  return myval

Got it!

Thanks a lot @chvck