Failed to list bucket after delete create


A bucket is deleted and then created. After creating the bucket we list all the buckets on the server but intermittently fail to find the newly created bucket in the list. This seems like some race condition.
This was tested using Java SDK version 3.3.0.

Couchbase Server -
3 node cluster
Enterprise Edition 6.6.4 build 9961

Attaching the code for reproduction.

import com.couchbase.client.core.error.BucketNotFoundException;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class StartUsing {
  // Update these variables to point to your Couchbase Server instance and credentials.
  static String connectionString = "10.14.xx.xx";
  static String username = "Administrator";
  static String password = "xxx";
  static String bucketName = "travel-sample";
  static Cluster cluster = null;

  public static void main(String... args) {

    cluster = Cluster.connect(connectionString, username, password);
    BucketSettings b1 = getBuckets().get(0); // In this case server only has travel-sample bucket.

    getBuckets(); // Sometimes doesn't contain the newly created bucket.

  public static void deleteBucket(final String bucket) {
    System.out.println("Deleting bucket " + bucket);
    try {
        try {
            System.out.println("Deleted bucket " + bucket);
        } catch (BucketNotFoundException e) {
        System.out.println("Bucket " + bucket + " not found on server.");
    } catch (Exception e) {
      throw new RuntimeException("Failed to delete bucket " + bucket, e);

  public static void createBucket(final BucketSettings bucket) {
    System.out.println("Creating bucket with Json " + bucket);
    System.out.println("Created bucket [" + + "].");

  public static List<BucketSettings> getBuckets() {
    Collection<BucketSettings> buckets;
    try {
      buckets = cluster.buckets().getAllBuckets().values();

      System.out.println("Found " + Arrays.toString(buckets.toArray()));
    } catch (Exception e) {
        System.out.println("Getting buckets failed.");
      throw e;
    return new ArrayList<BucketSettings>(buckets);

@sourish that’s because the operations are not atomic - they are eventually consistent on the cluster side. You can try fetching the buckets and sleeping a bit and fetching again until the bucket is found.

@daschl Thanks for the quick response.

You can try fetching the buckets and sleeping a bit and fetching again until the bucket is found

Yes, this workaround works fine and we’re already using it.