-
Notifications
You must be signed in to change notification settings - Fork 99
MONGOCRYPT-763 add in-place retry API #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
ce988fd
f615153
4cb5326
ab662af
db1b417
ac957c9
63b36a2
7e44b5f
d2951a4
1b18ce8
9d920b8
33f4c26
9745fa7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,8 +248,8 @@ Ensure `mongocrypt_setopt_retry_kms` is called on the `mongocrypt_t` to enable r | |
d. Feed the reply back with `mongocrypt_kms_ctx_feed`. Repeat | ||
> until `mongocrypt_kms_ctx_bytes_needed` returns 0. | ||
|
||
If any step encounters a network error, call `mongocrypt_kms_ctx_fail`. | ||
If `mongocrypt_kms_ctx_fail` returns true, continue to the next KMS context. | ||
If any step encounters a network error or if `mongocrypt_kms_ctx_should_retry` returns true after feeding the reply, call `mongocrypt_kms_ctx_fail`. | ||
If `mongocrypt_kms_ctx_fail` returns true, retry the request by continuing to the next KMS context or by feeding the new response into the same context. | ||
kevinAlbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
If `mongocrypt_kms_ctx_fail` returns false, abort and report an error. Consider wrapping the error reported in `mongocrypt_kms_ctx_status` to include the last network error. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The note below might be confusing, since it mentions fanning out requests with the older retry behavior:
Consider adding a section describing retry and iteration. Idea:
|
||
2. When done feeding all replies, call `mongocrypt_ctx_kms_done`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1120,6 +1120,28 @@ static bool _ctx_done_kmip_decrypt(mongocrypt_kms_ctx_t *kms_ctx) { | |
return ret; | ||
} | ||
|
||
static bool _is_retryable_req(_kms_request_type_t req_type) { | ||
// Check if request type is retryable. Some requests are non-idempotent and cannot be safely retried. | ||
_kms_request_type_t retryable_types[] = {MONGOCRYPT_KMS_AZURE_OAUTH, | ||
MONGOCRYPT_KMS_GCP_OAUTH, | ||
MONGOCRYPT_KMS_AWS_ENCRYPT, | ||
MONGOCRYPT_KMS_AWS_DECRYPT, | ||
MONGOCRYPT_KMS_AZURE_WRAPKEY, | ||
MONGOCRYPT_KMS_AZURE_UNWRAPKEY, | ||
MONGOCRYPT_KMS_GCP_ENCRYPT, | ||
MONGOCRYPT_KMS_GCP_DECRYPT}; | ||
for (size_t i = 0; i < sizeof(retryable_types) / sizeof(retryable_types[0]); i++) { | ||
if (retryable_types[i] == req_type) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool mongocrypt_kms_ctx_should_retry(mongocrypt_kms_ctx_t *kms) { | ||
return kms && kms->should_retry; | ||
} | ||
|
||
bool mongocrypt_kms_ctx_fail(mongocrypt_kms_ctx_t *kms) { | ||
if (!kms) { | ||
return false; | ||
|
@@ -1138,23 +1160,7 @@ bool mongocrypt_kms_ctx_fail(mongocrypt_kms_ctx_t *kms) { | |
return false; | ||
} | ||
|
||
// Check if request type is retryable. Some requests are non-idempotent and cannot be safely retried. | ||
_kms_request_type_t retryable_types[] = {MONGOCRYPT_KMS_AZURE_OAUTH, | ||
MONGOCRYPT_KMS_GCP_OAUTH, | ||
MONGOCRYPT_KMS_AWS_ENCRYPT, | ||
MONGOCRYPT_KMS_AWS_DECRYPT, | ||
MONGOCRYPT_KMS_AZURE_WRAPKEY, | ||
MONGOCRYPT_KMS_AZURE_UNWRAPKEY, | ||
MONGOCRYPT_KMS_GCP_ENCRYPT, | ||
MONGOCRYPT_KMS_GCP_DECRYPT}; | ||
bool is_retryable = false; | ||
for (size_t i = 0; i < sizeof(retryable_types) / sizeof(retryable_types[0]); i++) { | ||
if (retryable_types[i] == kms->req_type) { | ||
is_retryable = true; | ||
break; | ||
} | ||
} | ||
if (!is_retryable) { | ||
if (!_is_retryable_req(kms->req_type)) { | ||
CLIENT_ERR("KMS request failed due to network error"); | ||
return false; | ||
} | ||
|
@@ -1178,6 +1184,10 @@ bool mongocrypt_kms_ctx_feed(mongocrypt_kms_ctx_t *kms, mongocrypt_binary_t *byt | |
if (!mongocrypt_status_ok(status)) { | ||
return false; | ||
} | ||
if (kms->should_retry) { | ||
// This happens when a KMS context is reused in-place | ||
kms->should_retry = false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With Consider making this an error: if (kms->should_retry) {
CLIENT_ERR ("KMS context needs retry. Call mongocrypt_kms_ctx_feed_with_retry instead");
return false;
} And setting |
||
|
||
if (!bytes) { | ||
CLIENT_ERR("argument 'bytes' is required"); | ||
|
mdb-ad marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
HTTP/1.1 200 OK | ||
x-amzn-RequestId: deeb35e5-4ecb-4bf1-9af5-84a54ff0af0e | ||
Content-Type: application/x-amz-json-1.1 | ||
Content-Length: 446 | ||
Connection: close | ||
|
||
{"KeyId": "arn:aws:k |
Uh oh!
There was an error while loading. Please reload this page.