Skip to content

Commit 54ee477

Browse files
authored
Use Request timeout for on premises store login
1 parent dfb7e1e commit 54ee477

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1313
- QueryRequest.get/setNumberOfOperations()
1414
- QueryRequest.get/setOperationNumber()
1515
- Added new cloud region codes: hsg, abl, dfw, pbv, nbq, ibg, pcz, mez, den, kal
16-
- Added rowMetadata support, new API for Get/Put/Delete/MultiDelete request and result
17-
get/set RomMetadata.
18-
- Added row creation time support, new API: GetResult getCreationTime(),
16+
- Added rowMetadata support, new API for Get/Put/Delete/MultiDelete request and
17+
result get/set RowMetadata.
18+
- Added row creation time support, new API: GetResult getCreationTime(),
1919
Put/Delete/Write/WriteMultiple Result getExistingCreationTime().
2020

2121
## [5.4.17] 2025-03-03
@@ -29,6 +29,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
2929

3030
### Changed
3131
- Update netty dependency to 4.1.118.Final
32+
- Authentication calls for on premises login will now honor the request timeout
33+
rather than using a hard-coded 30s timeout
34+
3235

3336
## [5.4.16] 2024-11-21
3437

driver/src/main/java/oracle/nosql/driver/http/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ public Result execute(Request kvRequest) {
798798
if (authProvider instanceof StoreAccessTokenProvider) {
799799
final StoreAccessTokenProvider satp =
800800
(StoreAccessTokenProvider) authProvider;
801-
satp.bootstrapLogin();
801+
satp.bootstrapLogin(kvRequest);
802802
kvRequest.addRetryException(rae.getClass());
803803
kvRequest.incrementRetries();
804804
exception = rae;

driver/src/main/java/oracle/nosql/driver/kv/StoreAccessTokenProvider.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ public class StoreAccessTokenProvider implements AuthorizationProvider {
8282
private static final String LOGOUT_SERVICE = "/logout";
8383

8484
/*
85-
* Default timeout when sending http request to server
85+
* Default timeout when sending http request to server if not specified
86+
* by a request timeout. This is fairly long because it is usually
87+
* performed in an async fashion from a timer task and not in the
88+
* request path
8689
*/
87-
private static final int HTTP_TIMEOUT_MS = 30000;
90+
private static final int HTTP_TIMEOUT_MS = 20000;
8891

8992
/*
9093
* Authentication string which contain the Bearer prefix and login token's
@@ -220,7 +223,7 @@ public StoreAccessTokenProvider(String userName,
220223
*
221224
* Bootstrap login using the provided credentials
222225
*/
223-
public synchronized void bootstrapLogin() {
226+
public synchronized void bootstrapLogin(Request request) {
224227

225228
/* re-check the authString in case of a race */
226229
if (!isSecure || isClosed || authString.get() != null) {
@@ -236,11 +239,16 @@ public synchronized void bootstrapLogin() {
236239
encodeToString((
237240
userName + ":" + String.valueOf(password)).getBytes());
238241

242+
/*
243+
* Use the request timeout for this operation if available
244+
*/
245+
int timeoutMs = (request != null ?
246+
request.getTimeoutInternal() : 0);
239247
/*
240248
* Send request to server for login token
241249
*/
242250
HttpResponse response = sendRequest(BASIC_PREFIX + encoded,
243-
LOGIN_SERVICE);
251+
LOGIN_SERVICE, timeoutMs);
244252

245253
/*
246254
* login fail
@@ -294,7 +302,7 @@ public String getAuthorizationString(Request request) {
294302
* the login token and generate the auth string.
295303
*/
296304
if (authString.get() == null) {
297-
bootstrapLogin();
305+
bootstrapLogin(request);
298306
}
299307
return authString.get();
300308
}
@@ -330,7 +338,7 @@ public synchronized void close() {
330338
*/
331339
try {
332340
final HttpResponse response =
333-
sendRequest(authString.get(), LOGOUT_SERVICE);
341+
sendRequest(authString.get(), LOGOUT_SERVICE, 0);
334342
if (response.getStatusCode() != HttpResponseStatus.OK.code()) {
335343
if (logger != null) {
336344
logger.info("Failed to logout user " + userName +
@@ -497,7 +505,8 @@ private String parseJsonResult(String jsonResult) {
497505
* authentication information.
498506
*/
499507
private HttpResponse sendRequest(String authHeader,
500-
String serviceName) throws Exception {
508+
String serviceName,
509+
int timeoutMs) throws Exception {
501510
HttpClient client = null;
502511
try {
503512
final HttpHeaders headers = new DefaultHttpHeaders();
@@ -509,11 +518,14 @@ private HttpResponse sendRequest(String authHeader,
509518
sslHandshakeTimeoutMs,
510519
serviceName,
511520
logger);
521+
if (timeoutMs == 0) {
522+
timeoutMs = HTTP_TIMEOUT_MS;
523+
}
512524
return HttpRequestUtil.doGetRequest(
513525
client,
514526
NoSQLHandleConfig.createURL(endpoint, basePath + serviceName)
515527
.toString(),
516-
headers, HTTP_TIMEOUT_MS, logger);
528+
headers, timeoutMs, logger);
517529
} finally {
518530
if (client != null) {
519531
client.shutdown();
@@ -560,7 +572,8 @@ public void run() {
560572
try {
561573
final String oldAuth = authString.get();
562574
HttpResponse response = sendRequest(oldAuth,
563-
RENEW_SERVICE);
575+
RENEW_SERVICE,
576+
0);
564577
final String token = parseJsonResult(response.getOutput());
565578
if (response.getStatusCode() != HttpResponseStatus.OK.code()) {
566579
throw new InvalidAuthorizationException(token);

driver/src/test/java/oracle/nosql/driver/kv/StoreAccessTokenProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private class TestMultiThreads implements Runnable {
185185
public void run() {
186186
try {
187187
for (int i = 0; i < 5; i++) {
188-
sap.bootstrapLogin();
188+
sap.bootstrapLogin(null);
189189
}
190190
} finally {
191191
sap.close();

0 commit comments

Comments
 (0)