Skip to content
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

jsonrpc: Wait for the socket to be ready to read. #11815

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brbzull0
Copy link
Contributor

We found out that sometimes we hit a busy loop here, so adding a timeout to make sure we do not hangup forever here.

We found out that sometimes we hit a busy loop here, so adding a timeout
to make sure we do not hangup forever here.
@brbzull0 brbzull0 self-assigned this Oct 10, 2024
@brbzull0 brbzull0 changed the title jsonrpc: Add poll to wait for the socket to be ready to read. jsonrpc: Wait for the socket to be ready to read. Oct 10, 2024
@brbzull0 brbzull0 added this to the 10.1.0 milestone Oct 10, 2024
@brbzull0 brbzull0 marked this pull request as ready for review October 11, 2024 10:17
Copy link
Contributor

@bneradt bneradt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. I'll let a non-Yahoo reviewer chime in.

Copy link
Contributor

@cmcfarlen cmcfarlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is correct. Should you call read_ready if there were some bytes read in previous iterations of the outer loop? Shouldn't a timeout from read_ready stop the inner loop? It seems like this will always wait until EOF or until (timeout_ms * attempts) have elapsed. The logic is a bit confusing, so maybe some comments about what is happening will clear it up.

@@ -30,12 +30,12 @@
#include "shared/rpc/MessageStorage.h"
#include <tscore/ink_assert.h>
#include <tscore/ink_sock.h>

#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header is unused.

@@ -117,23 +117,36 @@ IPCSocketClient ::send(std::string_view data)
}

IPCSocketClient::ReadStatus
IPCSocketClient::read_all(std::string &content)
IPCSocketClient::read_all(std::string &content, std::chrono::milliseconds timeout_ms, int attempts)
{
if (this->is_closed()) {
// we had a failure.
return {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not part of the changes, but this will return NO_ERROR? But the comment indicates a failure. Could UNKNOWN be a better return?

// done!
break;
}
} while (ret != 0 && attempts_left > 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check for readStatus timeout and error and also stop the loop? If you don't check for timeout, this function will wait for timeout_ms * attempts (10 seconds by default). What errors would poll return that we would want to retry?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants