Data is visible from other channels for a user

I have created a user for sync gateway with access to a particular channel . However I am seeing that all the documents not marked for that channel are also visible. This is the sample sync-gatewaycofnig file that I have

  "samplebucket": {
	      "import_docs": "continuous",
	      "enable_shared_bucket_access":true,  
	      "bucket":"samplebucket",
	      "server": "http://localhost:8091",
	      "username": "sync_gateway",
	      "password": "password",
	      "num_index_replicas":0,
	      "users":{
		  "GUEST": {"disabled":true},
		  "user1": {"password": "password", "admin_channels": ["channel1"]}
	      },
	      "revs_limit": 20,
	      "sync": `function (doc, oldDoc) { 
		           if (doc.IsChannel1 == true) {
		           channel("Channel1");
		           }
		          else {
		          channel("ChannelX");
		          }
	      }`      
  }

I do see that the channels are assigned to individual documents in the sync gateway admin portal.
However when I run the following code, it prints all the documents in the bucket rather than just the documents from channel1:

    Endpoint targetEndpoint = new URLEndpoint(new URI(SYNC_GATEWAY_URL));
    ReplicatorConfiguration replConfig = new ReplicatorConfiguration(database, targetEndpoint);
    replConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PULL);
    replConfig.setContinuous(false);


    // Add authentication.
    replConfig.setAuthenticator(new BasicAuthenticator("user1", "password"));

    // Create replicator (be sure to hold a reference somewhere that will prevent the Replicator from being GCed)
    Replicator replicator = new Replicator(replConfig);

    // Listen to replicator change events.
    replicator.addChangeListener(change -> {
        if (change.getStatus().getError() != null) {
            System.err.println("Error code ::  " + change.getStatus().getError().getCode());
        }
    });

    // Start replication.
    replicator.start();

    // Check status of replication and wait till it is completed
    while (replicator.getStatus().getActivityLevel() != Replicator.ActivityLevel.STOPPED) {
        Thread.sleep(1000);
    }
// print query results from cb lite
    Query queryAll = QueryBuilder.select(SelectResult.expression(Meta.id))
            .from(DataSource.database(database));
    try {
        for (Result thisDoc : queryAll.execute()) {
            numRows++;
            System.out.println(String.format("%d ... Id: %s ",
                    numRows,
                    thisDoc.getString(Prop_Id)
            ));
        }
    } catch (CouchbaseLiteException e) {
        e.printStackTrace();
    }

How are you exactly verifying that the document to channel assignment is happening correctly. FFR, please do not use the adminUI. This is an unsupported feature.
Please output the results the _raw API or all_docs filtered by channels

Couple of things that may be happening

  • Not 100% sure if it matters but you may want to align the case associated with the channel names (you have “channel1” and “Channel1” respectively)
  • It is possible that you updated the sync function after the documents were already synced down by the clients

So as a next step, would suggest following

  • Add a new document that you expect to be assigned exclusively to ChannelX
  • Share _raw API output to confirm channels that document is assigned to is correct
  • Share the log output of the couchbase lite log query