Skip to content

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
@DHowett
Copy link
Member

DHowett commented Dec 2, 2024

Hey @lhecker, could this be #18275

image

@lhecker
Copy link
Member Author

lhecker commented Dec 2, 2024

I only observed an issue during tear-down, but it's very well possible that this is the same issue.
Edit: On second thought, it's unlikely, because the callback does not take a parameter.

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.

4 participants