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

Defuse throttled_func when it's accidentally engaged #18235

Merged
merged 3 commits into from
Nov 25, 2024

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Nov 22, 2024

This change prevents throttled_func from reading uninitialized memory
under some yet-unkown circumstances. The tl;dr is:
This simply moves the callback invocation into the storage.
That way we can centrally avoid invoking the callback accidentally.

@lhecker lhecker added Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Priority-3 A description (P3) labels Nov 22, 2024
@lhecker
Copy link
Member Author

lhecker commented Nov 22, 2024

BTW there's a good chance that this bug was caused by a miscompilation. Lately I've had A LOT of crashes in random code which go away with a clean build. To be fair, I'm using the latest preview version of VS, but there may be some fun times coming for us.

decltype(_pendingRunArgs) args;
{
std::unique_lock guard{ _lock };
args = std::exchange(_pendingRunArgs, std::nullopt);
Copy link
Member Author

Choose a reason for hiding this comment

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

As suggested by Dustin, this now uses std::exchange.

{
_trailing_edge();
}
_timer_callback(nullptr, this, nullptr);
Copy link
Member Author

Choose a reason for hiding this comment

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

Reading this code I've realized that I can ever so slightly reduce the binary size by moving _trailing_edge into the _timer_callback and calling _timer_callback directly.

Copy link
Member

Choose a reason for hiding this comment

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

It depends honestly. If all of timer_callback is larger and less deduplicatable with COMDAT folding, it could be larger overall.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, I think I see what you mean. It does have the additional benefit that it swallows the exception, just like the regular timer callback. This makes it more predictable IMO, because it now behaves identical.

@DHowett DHowett enabled auto-merge (squash) November 25, 2024 23:00
@DHowett DHowett merged commit adac608 into main Nov 25, 2024
18 of 20 checks passed
@DHowett DHowett deleted the dev/lhecker/throttled-func-safety branch November 25, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants