Go SDK Client Reconnect

Hi,

I have a very simple Go program that saves json data to the default couchbase 4 bucket.

If I stop/start my couchbase 4 single node instance my Go program looses it’s connection to the cluster (single node).

Shouldn’t the Go SDK client code reconnect?

I’d like the client to continuously try reconnect (no timeout ever).

The code I’ve written is on github at github.com/rudijs/urban

The client connection is in main.go:27

Thanks.

Or should I be re-connecting in the code myself if an upsert (or something) fails?

Thanks.

I’ve simplified my code example to just a single main.go file.

There’s a loop that upserts documents into Couchbase 4 using the Go SDK.

As you enter documents, they get upserted.

Here’s some details of the behavior of the upsert as Couchbase 4 is stopped and started while using the same running Go process:

  • Start Couchbase 4
  • Start Go program and enter in some JSON documents
❯ go run main.go
==> Enter a JSON document:
{"id":101}
Inserted document CAS is `140ed05555b70000`
==> Enter a JSON document:
{"id":102}
Inserted document CAS is `140ed0572b680000`
  • Stop Couchbase 4
  • Enter in more documents from the same running Go program
==> Enter a JSON document:
{"id":103}
ERROR: The operation has timed out.
==> Enter a JSON document:
{"id":104}
ERROR: The operation has timed out.
==> Enter a JSON document:
  • Restart Couchbase 4
  • Enter in more documents from the same running Go program
{"id":105}
ERROR: The operation has timed out.
==> Enter a JSON document:

So we can see the Go SDK client is not reconnecting.

  • Exit and the start again the Go program, which will then reconnect to Couchbase 4
==> Enter a JSON document:
^Cexit status 2
/m/r/c/p/g/s/g/r/couchbase4-gosdk ❯❯❯ go run main.go                                                                                           ⏎
==> Enter a JSON document:
{"id":106}
Inserted document CAS is `140ed07055fc0000`
==> Enter a JSON document:

So now at the end of this process Couchbase 4 has documents 101, 102 and 106

Documents 103 and 104 were not upserted as Couchbase 4 was off.

Document 105 was not upserted even though Couchbase was running again.

What would be some idiomatic Go lang approaches to re-try and/or reconnect?

Hey @rudijs,

Indeed the Go SDK should reconnect when the server returns to working order. I will investigate and see if I can narrow down a root cause. https://issues.couchbase.com/browse/GOCBC-69

Cheers, Brett

@brett19 Hey Brett, OK great - please let me know if I can help in any way.

Cheers.