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

Fix #3167: avoid infinite wait on failure to init curl handle acquire #3200

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

SergeyRyabinin
Copy link
Contributor

Issue #, if available:
#3167
Description of changes:

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

const bool isNotEmpty = m_semaphore.wait_for(locker, std::chrono::milliseconds(timeoutMs),
[&]() { return m_shutdown.load() || !m_resources.empty(); });

if (m_shutdown || !isNotEmpty) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit ! and isNot is kind of confusing could we just use isEmpty instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

wait_for returns an enum.
https://en.cppreference.com/w/cpp/thread/condition_variable/wait_for
Better to use this .
enum class cv_status {
no_timeout, => 0
timeout => 1
};

doesm't that mean return on !isNotEmpty is actually returning on no timeout. Is that the intention?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, isNotEmpty can be renamed to isTimeOut for clarity

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test case to test the timeout scenario, which should be easy to replicate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it doesn't return an enum. Check the spec you linked for the (2) with predicate.

Copy link
Contributor

Choose a reason for hiding this comment

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

that's right. looks ok then. if you can add a test case that will be great

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a really hard to test this piece of code: curl wrapper is hard-coded to a real c curl APIs, handle container is private and cannot be replaced.
I have a 1y old draft of curl wrapper refactoring: https://github.com/aws/aws-sdk-cpp/tree/sr/curlMulti2 which I still want to have merged one day. I can add curl wrapper unit tests there.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test on ResourceManager template class.

bool errorLogged = false; // avoid log explosion on legacy app behavior
while (!handle && m_poolSize) {
constexpr unsigned long DEFAULT_TIMEOUT = 1000l;
handle = m_handleContainer.TryAcquire(std::max(m_connectTimeout, DEFAULT_TIMEOUT));
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we should use something else besides m_connectTimeout as that maps one to one with CURLOPT_CONNECTTIMEOUT_MS, and we are sort of tying those together. this has its own unique meaning of "aquisition from the pool time", not "DNS lookup time". maybe create a static const/maybe add a config var if this would touch several clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed usage of m_connectTimeout, and just set 1s of wait time.

@SergeyRyabinin SergeyRyabinin force-pushed the sr/i3167 branch 2 times, most recently from 06a6b0c to cd36e12 Compare November 19, 2024 21:36
@SergeyRyabinin SergeyRyabinin marked this pull request as ready for review November 19, 2024 22:58
@SergeyRyabinin SergeyRyabinin force-pushed the sr/i3167 branch 3 times, most recently from 783ebe7 to c57b664 Compare November 19, 2024 23:33
@SergeyRyabinin SergeyRyabinin merged commit aa4382d into main Nov 20, 2024
5 checks passed
@SergeyRyabinin SergeyRyabinin deleted the sr/i3167 branch November 20, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants