Skip to content

Commit ab662af

Browse files
committed
Combine fail and reset
1 parent 4cb5326 commit ab662af

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

src/mongocrypt-kms-ctx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ static bool _is_retryable_req(_kms_request_type_t req_type) {
11381138
return false;
11391139
}
11401140

1141-
bool mongocrypt_kms_ctx_should_retry_http(mongocrypt_kms_ctx_t *kms) {
1141+
bool mongocrypt_kms_ctx_should_retry(mongocrypt_kms_ctx_t *kms) {
11421142
return kms && kms->should_retry;
11431143
}
11441144

@@ -1191,6 +1191,10 @@ bool mongocrypt_kms_ctx_feed(mongocrypt_kms_ctx_t *kms, mongocrypt_binary_t *byt
11911191
if (!mongocrypt_status_ok(status)) {
11921192
return false;
11931193
}
1194+
if (kms->should_retry) {
1195+
// This happens when a KMS context is reused in-place
1196+
kms->should_retry = false;
1197+
}
11941198

11951199
if (!bytes) {
11961200
CLIENT_ERR("argument 'bytes' is required");

src/mongocrypt.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,8 @@ MONGOCRYPT_EXPORT
11801180
bool mongocrypt_kms_ctx_feed(mongocrypt_kms_ctx_t *kms, mongocrypt_binary_t *bytes);
11811181

11821182
/**
1183-
* Indicate a network-level failure.
1183+
* Indicate a failure. Discards all data fed to this KMS context with @ref mongocrypt_kms_ctx_feed.
1184+
* The @ref mongocrypt_kms_ctx_t may be reused.
11841185
*
11851186
* @param[in] kms The @ref mongocrypt_kms_ctx_t.
11861187
* @return A boolean indicating whether the failed request may be retried.
@@ -1189,21 +1190,13 @@ MONGOCRYPT_EXPORT
11891190
bool mongocrypt_kms_ctx_fail(mongocrypt_kms_ctx_t *kms);
11901191

11911192
/**
1192-
* Reset a KMS context allowing it to be retried.
1193+
* Indicate if a KMS context is completed but should be retried.
11931194
*
11941195
* @param[in] kms The @ref mongocrypt_kms_ctx_t.
1196+
* @return A boolean indicating whether the failed request should be retried.
11951197
*/
11961198
MONGOCRYPT_EXPORT
1197-
void mongocrypt_kms_ctx_reset(mongocrypt_kms_ctx_t *kms);
1198-
1199-
/**
1200-
* Indicate if a KMS context is completed but should be retried due to an HTTP error.
1201-
*
1202-
* @param[in] kms The @ref mongocrypt_kms_ctx_t.
1203-
* @return A boolean indicating whether the failed request is complete but should be retried.
1204-
*/
1205-
MONGOCRYPT_EXPORT
1206-
bool mongocrypt_kms_ctx_should_retry_http(mongocrypt_kms_ctx_t *kms);
1199+
bool mongocrypt_kms_ctx_should_retry(mongocrypt_kms_ctx_t *kms);
12071200

12081201
/**
12091202
* Get the status associated with a @ref mongocrypt_kms_ctx_t object.

test/test-mongocrypt-datakey.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ static void _test_create_datakey_with_retry(_mongocrypt_tester_t *tester) {
444444
// Feed a retryable HTTP error.
445445
ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx, TEST_FILE("./test/data/rmd/kms-decrypt-reply-429.txt")), kms_ctx);
446446
// In-place retry is indicated.
447-
ASSERT(mongocrypt_kms_ctx_should_retry_http(kms_ctx));
448-
mongocrypt_kms_ctx_reset(kms_ctx);
447+
ASSERT(mongocrypt_kms_ctx_should_retry(kms_ctx));
448+
ASSERT(mongocrypt_kms_ctx_fail(kms_ctx));
449449
// Feed a successful response.
450450
ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx, TEST_FILE("./test/data/kms-aws/encrypt-response.txt")), kms_ctx);
451451
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
@@ -497,8 +497,6 @@ static void _test_create_datakey_with_retry(_mongocrypt_tester_t *tester) {
497497
ASSERT_CMPINT64(mongocrypt_kms_ctx_usleep(kms_ctx), ==, 0);
498498
// Mark a network error.
499499
ASSERT_OK(mongocrypt_kms_ctx_fail(kms_ctx), kms_ctx);
500-
// Reset the context.
501-
mongocrypt_kms_ctx_reset(kms_ctx);
502500
// Feed a successful response.
503501
ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx, TEST_FILE("./test/data/kms-aws/encrypt-response.txt")), kms_ctx);
504502
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);

0 commit comments

Comments
 (0)