Skip to content

Commit 946991b

Browse files
committed
JVMCBC-1477 Improve config loading backoff for bad credentials
Motivation ---------- Prior to this change, providing bad credentials and then opening a bucket caused the SDK to spam the server with unauthorized (401) "GET /pools/default/b/<bucket-name>" requests. These requests flooded the server's http_access.log. Modifications ------------- Add "no access" to the category of errors that get a longer delay between retries. Change-Id: I93473c5b08d2d9f12448a8fba2e879ecaa9539cd Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/207418 Tested-by: Build Bot <[email protected]> Reviewed-by: Michael Reiche <[email protected]>
1 parent 4580131 commit 946991b

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

core-io/src/main/java/com/couchbase/client/core/config/DefaultConfigurationProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.couchbase.client.core.error.BucketNotReadyDuringLoadException;
4949
import com.couchbase.client.core.error.ConfigException;
5050
import com.couchbase.client.core.error.CouchbaseException;
51+
import com.couchbase.client.core.error.NoAccessDuringConfigLoadException;
5152
import com.couchbase.client.core.error.RequestCanceledException;
5253
import com.couchbase.client.core.error.SeedNodeOutdatedException;
5354
import com.couchbase.client.core.error.TimeoutException;
@@ -973,9 +974,10 @@ private Mono<ProposedBucketConfigContext> fetchBucketConfigs(final String name,
973974

974975
boolean bucketNotFound = f instanceof BucketNotFoundDuringLoadException;
975976
boolean bucketNotReady = f instanceof BucketNotReadyDuringLoadException;
977+
boolean noAccess = f instanceof NoAccessDuringConfigLoadException;
976978

977-
// For bucket not found or not ready wait a bit longer, retry the rest quickly
978-
Duration delay = bucketNotFound || bucketNotReady
979+
// For some, wait a bit longer; retry the rest quickly.
980+
Duration delay = bucketNotFound || bucketNotReady || noAccess
979981
? Duration.ofMillis(500)
980982
: Duration.ofMillis(1);
981983
eventBus.publish(new BucketOpenRetriedEvent(name, delay, core.context(), f));

core-io/src/main/java/com/couchbase/client/core/config/loader/ClusterManagerBucketLoader.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.couchbase.client.core.Reactor;
2222
import com.couchbase.client.core.error.BucketNotFoundDuringLoadException;
2323
import com.couchbase.client.core.error.ConfigException;
24-
import com.couchbase.client.core.msg.ResponseStatus;
24+
import com.couchbase.client.core.error.NoAccessDuringConfigLoadException;
2525
import com.couchbase.client.core.msg.manager.BucketConfigRequest;
2626
import com.couchbase.client.core.node.NodeIdentifier;
2727
import com.couchbase.client.core.retry.BestEffortRetryStrategy;
@@ -72,10 +72,14 @@ protected Mono<byte[]> discoverConfig(final NodeIdentifier seed, final String bu
7272
}).map(response -> {
7373
if (response.status().success()) {
7474
return response.config();
75-
} else if (response.status() == ResponseStatus.NOT_FOUND) {
76-
throw new BucketNotFoundDuringLoadException("Bucket [\"" + redactMeta(bucket) + "\"] not found during loading");
77-
} else {
78-
throw new ConfigException("Received error status from ClusterManagerBucketLoader: " + response);
75+
}
76+
switch (response.status()) {
77+
case NOT_FOUND:
78+
throw new BucketNotFoundDuringLoadException("Bucket [\"" + redactMeta(bucket) + "\"] not found during loading");
79+
case NO_ACCESS:
80+
throw new NoAccessDuringConfigLoadException("Client was denied access to bucket [\"" + redactMeta(bucket) + "\"] during config loading. Common causes include invalid credentials or insufficient permissions.");
81+
default:
82+
throw new ConfigException("Received error status from ClusterManagerBucketLoader: " + response);
7983
}
8084
});
8185
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2024 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.couchbase.client.core.error;
18+
19+
import com.couchbase.client.core.annotation.Stability;
20+
21+
@Stability.Internal
22+
public class NoAccessDuringConfigLoadException extends ConfigException {
23+
public NoAccessDuringConfigLoadException(String message) {
24+
super(message);
25+
}
26+
}

0 commit comments

Comments
 (0)