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

Addition of an option to throttle the signing requests. #159

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

hikariuk
Copy link
Contributor

Even with the -mdop option set to 1 I still periodically get errors from timestamp servers, so this option attempts to add another tool to the chest to prevent this.

Chris Crowther added 3 commits April 13, 2022 08:09
Largely added because even with "--mdop 1" I still periodically get errors from timestamp servers.
Copy link
Owner

@vcsjones vcsjones left a comment

Choose a reason for hiding this comment

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

In theory I like this idea, but I do not think AzureSign.Core should be changed. This seems more like a change with how AzureSignTool interacts with AzureSign.Core. AzureSign.Core's job is to just sign things, unaware of its surroundings.

I would consider moving the throttling and tracking to somewhere here:

Parallel.ForEach(AllFiles, options, () => (succeeded: 0, failed: 0), (filePath, pls, state) =>

@hikariuk
Copy link
Contributor Author

In theory I like this idea, but I do not think AzureSign.Core should be changed. This seems more like a change with how AzureSignTool interacts with AzureSign.Core. AzureSign.Core's job is to just sign things, unaware of its surroundings.

I'll shift the changes to the loop. Makes the changes a bit simpler too, really.

@hikariuk hikariuk requested a review from vcsjones April 21, 2022 17:54
@wizgob
Copy link

wizgob commented Oct 6, 2022

Is this possible to validate this PR? I also experience throttling with my timestamp provider.

Copy link
Owner

@vcsjones vcsjones left a comment

Choose a reason for hiding this comment

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

Just some questions and ideas for improving reliability.

{
DateTime goTime = _lastSigningOperation.AddSeconds(SigningThrottle.Value);

if (goTime >= DateTime.Now)
Copy link
Owner

Choose a reason for hiding this comment

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

I have some concerns around this since DateTime.Now is not monotonic - for example, a Daylight Saving Time. Let's say the _lastSigningOperation is at 1:59 AM. Day Light Savings kicks in at 2:00 AM, and jumps forward to 3:00 AM. This will violate the throttle.

Using DateTimeOffset.UtcNow probably mitigates most of those concerns... except for things like clock correction. I think that is a tradeoff I am willing to accept. A "true" monotonic clock source is probably overkill for this purpose.

Can we re-work this to use DateTimeOffset.UtcNow?

Copy link
Contributor Author

@hikariuk hikariuk Aug 13, 2023

Choose a reason for hiding this comment

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

Could possibly use System.Threading.PeriodicTimer instead, which was added at some point, but I'd need to check the version availability for it. You just call the wait method on the class; it'll return immediately if there's already been one or more ticks since the method was last called, or it will wait until there is one and then return.

@@ -96,7 +99,9 @@ internal sealed class SignCommand
[Argument(0, "file", "The path to the file.")]
public string[] Files { get; set; } = Array.Empty<string>();

private static DateTime _lastSigningOperation;
Copy link
Owner

Choose a reason for hiding this comment

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

Does this need to be static? Does it even need to be a field, or can it be part of the state in Parallel.ForEach?

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's been a while since I wrote this and I'll have to double check whether throttling limits it you to a single request thread. I have a feeling I made it so that it did; if I did then there's not really any need for it to be static and I'll pull it in to the state.

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