It’s a known detail that Couchbase takes some time to startup, and trying to connect to a cluster before it’s fully initialized can leave the SDK in an odd state. It’s a problem I’ve encountered a lot for local machine development, where we script up Couchbase in Docker.
There is an open issue on the Server to make this more monitorable: https://issues.couchbase.com/browse/MB-11484
In the meantime, you can look at the work I’ve done on “couchbasefakeit” to help address the problem. You could either use it directly, or pull out the pieces you need. GitHub - brantburnett/couchbasefakeit: Docker scripts for a base Couchbase Server image for testing/development, with support for fakeit for data generation
It fully initializes the cluster with indexes, fake data, and more. Once complete, it writes out a “/notestatus/initialized” file to disk. I share that file with my application via a Docker volume mount, and set my application to watch for this file (local dev only) before app startup. It’s not elegant, but it works.