Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

fix: Adjust big segments logic to prevent duplicate polls. #225

Merged
merged 2 commits into from
May 31, 2024

Conversation

kinyoklion
Copy link
Member

@kinyoklion kinyoklion commented May 31, 2024

The contract tests attempt to determine that the SDK is not making redundant polls, and sometimes this test would fail.

Theoretically this could also affect a server handling requests on many threads which concurrently request status before the first request has completed.

@@ -43,8 +44,9 @@ Logger logger
_taskExecutor = taskExecutor;
_logger = logger;

_initialPoll = Task.Run(PollStoreAndUpdateStatusAsync);
Copy link
Member Author

Choose a reason for hiding this comment

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

Manually run the first task instead of using the repeating task.

return ret.Value;
}
return AsyncUtils.WaitSafely(() => PollStoreAndUpdateStatusAsync());
return ret ?? _initialPoll.GetAwaiter().GetResult();
Copy link
Member Author

Choose a reason for hiding this comment

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

If there is no value, then that first poll has not completed. Wait for it to complete.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that the initial task is still executing by the time the first repeating task runs? I suppose it may be extremely unlikely given the real world values of StatusPollInterval.

Copy link
Member Author

Choose a reason for hiding this comment

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

It theoretically is possible. I did consider if there was a way to use the most recent task, but the complexity didn't seem worth it. If at any point a repeating task does complete, then we would ideally hit the first code path subsequently.

@kinyoklion kinyoklion marked this pull request as ready for review May 31, 2024 16:39
@kinyoklion kinyoklion requested a review from a team May 31, 2024 16:39
return ret.Value;
}
return AsyncUtils.WaitSafely(() => PollStoreAndUpdateStatusAsync());
return ret ?? _initialPoll.GetAwaiter().GetResult();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that the initial task is still executing by the time the first repeating task runs? I suppose it may be extremely unlikely given the real world values of StatusPollInterval.

@kinyoklion kinyoklion merged commit 4202165 into main May 31, 2024
8 checks passed
@kinyoklion kinyoklion deleted the rlamb/de-duplicate-status-requests branch May 31, 2024 19:58
kinyoklion pushed a commit that referenced this pull request Jun 3, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.5.1](8.5.0...8.5.1)
(2024-06-03)


### Bug Fixes

* Adjust big segments logic to prevent duplicate polls.
([#225](#225))
([4202165](4202165))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants