-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4700 - Convert CSFLE tests to async #1907
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
Conversation
@@ -145,6 +145,8 @@ def _is_ready(fut: Future) -> None: | |||
read = conn.recv_into(mv[total_read:]) | |||
if read == 0: | |||
raise OSError("connection closed") | |||
if once: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to support KMS requests, which require that the read returns the first batch immediately to accurately update the expected length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't sound right. If we know how much we need to read we should be looping until we read that amount.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop inside _async_kms_request
changes kms_context.bytes_needed
with each recv
and feed
call. If we allow async_receive_data_socket
to run until the initial kms_context.bytes_needed
number of bytes is read, it will result in an error.
while kms_context.bytes_needed > 0:
# CSOT: update timeout.
conn.settimeout(max(_csot.clamp_remaining(_KMS_CONNECT_TIMEOUT), 0))
data = await async_receive_data_socket(conn, kms_context.bytes_needed)
kms_context.feed(data)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the behavior I observed that led to this change:
kms_context.bytes_needed = N
async_receive_data_socket returns with X bytes read, X < N
kms_context.feed is called
kms_context.bytes_needed is now not N - X, but a different value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, looks like that's intentional behavior in libmongocrypt:
/* Before we've read the Content-Length header in an HTTP response,
* we don't know how many bytes we'll need. So return this value
* in kms_ctx_bytes_needed until we are fed the Content-Length.
*/
#define DEFAULT_MAX_KMS_BYTE_REQUEST 1024
https://github.com/mongodb/libmongocrypt/blob/7aeaec4/src/mongocrypt-kms-ctx.c#L47-L51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a little odd but this approach allows us to reuse as much code as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add Shane's note as a comment for future readers?
|
Maybe we need to skip that test and mark it for PYTHON-4493? |
Agree. I suggest opening a new ticket for the skipped test to make sure it doesn't get lost. |
Skipped in #1914. |
Somehow that test is still failing. |
33c19f4
to
24ba64a
Compare
I messed up the merge, fixed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.