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

Properly handle alternate console stream encodings in StaticGraphRestoreArguments #5010

Merged
merged 3 commits into from
Jan 23, 2023

Conversation

jeffkl
Copy link
Contributor

@jeffkl jeffkl commented Jan 18, 2023

Bug

Fixes: NuGet/Home#12373

Regression? Yes Last working version: 17.4

Description

When you enable alternate region encodings, Windows appears to write a preamble to Console.StandardInput causing the logic in StaticGraphRestoreArguments to fail to read the stream correctly.

My fix is to write take into account the encoding of the stream and skip the preamble if one is found. This is done by looking at the encoding's preamble, reading the first 4 bytes of the stream, skipping the preamble, and reading the next set of bytes. This results in the buffer containing the first integer in the stream so the rest of the code can read the content normally.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@jeffkl jeffkl requested a review from a team as a code owner January 18, 2023 19:32
@jeffkl jeffkl self-assigned this Jan 18, 2023
Forgind
Forgind previously approved these changes Jan 18, 2023
Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

I'm wondering if a specific random byte might be better in case someone else does something similar, but I think this is good 🙂

@jeffkl
Copy link
Contributor Author

jeffkl commented Jan 18, 2023

I'm wondering if a specific random byte might be better in case someone else does something similar, but I think this is good 🙂

Good point, it appears that both byte.MaxValue (255/0xFF) and byte.MinValue (0/0x00) can be used in the byte order mark. In my testing I was seeing 0xFF 0xBB 0xBF (UTF8 BOM) which wouldn't collide, but I need something more future proof. More research required...

donnie-msft
donnie-msft previously approved these changes Jan 18, 2023
@jeffkl
Copy link
Contributor Author

jeffkl commented Jan 18, 2023

I've realized now that I can emulate a stream with this functionality and write unit tests for it, will update soon...

@jeffkl jeffkl dismissed stale reviews from donnie-msft and Forgind via b9880ad January 19, 2023 04:06
@jeffkl jeffkl force-pushed the dev-jeffkl-fix-static-graph-restore-encoding branch from 3b179fd to b9880ad Compare January 19, 2023 04:06
@jeffkl
Copy link
Contributor Author

jeffkl commented Jan 19, 2023

I've completely revamped my implementation, please re-review!

@jeffkl jeffkl force-pushed the dev-jeffkl-fix-static-graph-restore-encoding branch from b9880ad to 5b3639b Compare January 19, 2023 16:58
zivkan
zivkan previously approved these changes Jan 20, 2023
@jeffkl jeffkl merged commit 6512bed into dev Jan 23, 2023
@jeffkl jeffkl deleted the dev-jeffkl-fix-static-graph-restore-encoding branch January 23, 2023 16:09
AR-May added a commit to dotnet/msbuild that referenced this pull request Feb 24, 2023
Our CI builds fails because of bug NuGet/Home#12373. 
It is fixed in NuGet/NuGet.Client#5010. 
We are waiting for it to flow to CI machines. Meanwhile this PR applies a workaround.

Note: This PR needs to be reverted once it happens.
jeffkl added a commit that referenced this pull request Mar 8, 2023
jeffkl added a commit that referenced this pull request Mar 9, 2023
…ts to standard input (#5080)

* Revert "Properly handle alternate console stream encodings in StaticGraphRestoreArguments (#5010)"

This reverts commit 6512bed.

* Revert "Write static graph restore arguments to standard input instead of passing on the command-line (#4772)"

This reverts commit 19a4170.
rokonec pushed a commit to rokonec/msbuild that referenced this pull request Mar 10, 2023
Our CI builds fails because of bug NuGet/Home#12373. 
It is fixed in NuGet/NuGet.Client#5010. 
We are waiting for it to flow to CI machines. Meanwhile this PR applies a workaround.

Note: This PR needs to be reverted once it happens.
rokonec pushed a commit to rokonec/msbuild that referenced this pull request Mar 14, 2023
Our CI builds fails because of bug NuGet/Home#12373. 
It is fixed in NuGet/NuGet.Client#5010. 
We are waiting for it to flow to CI machines. Meanwhile this PR applies a workaround.

Note: This PR needs to be reverted once it happens.
rokonec added a commit to dotnet/msbuild that referenced this pull request Mar 14, 2023
…emetry instance (#8561)

* BuildManager instances acquire its own BuildTelemetry instance (#8444)

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1708215

Context
In VS there are multiple instances of BuildManager called asynchronously. For DTB and normal build and maybe other which I have not identified yet.

Changes Made
BuildManager instances acquire its own BuildTelemetry instance as oppose to sharing single BuildTelemetry instance in non thread safe manner.

Testing
Locally
# Conflicts:
#	src/Build/BackEnd/Client/MSBuildClient.cs - resolved with minimal and safe approach

* Bumping version

* Turn off static graph restore. (#8498)

Our CI builds fails because of bug NuGet/Home#12373. 
It is fixed in NuGet/NuGet.Client#5010. 
We are waiting for it to flow to CI machines. Meanwhile this PR applies a workaround.

Note: This PR needs to be reverted once it happens.

---------

Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
rokonec added a commit to dotnet/msbuild that referenced this pull request Mar 27, 2023
* Concurrency bug fix - BuildManager instances acquire its own BuildTelemetry instance (#8561)

* BuildManager instances acquire its own BuildTelemetry instance (#8444)

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1708215

Context
In VS there are multiple instances of BuildManager called asynchronously. For DTB and normal build and maybe other which I have not identified yet.

Changes Made
BuildManager instances acquire its own BuildTelemetry instance as oppose to sharing single BuildTelemetry instance in non thread safe manner.

Testing
Locally
# Conflicts:
#	src/Build/BackEnd/Client/MSBuildClient.cs - resolved with minimal and safe approach

* Bumping version

* Turn off static graph restore. (#8498)

Our CI builds fails because of bug NuGet/Home#12373. 
It is fixed in NuGet/NuGet.Client#5010. 
We are waiting for it to flow to CI machines. Meanwhile this PR applies a workaround.

Note: This PR needs to be reverted once it happens.

---------

Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>

* Use AutoResetEvent as oppose to ManualResetEventSlim (#8575)

Summary
Customer, mainly internal like XStore, with huge repos, using msbuild /graph /bl on powerful development and build computers, might experience 15x plus regression in evaluation time.

It has been identified as performance bug in our logging event pub/sub mechanism. When ingest queue reaches its bound, at .net472 ManualResetEventSlim causes way too many thread.Yields flooding the system with thread context switches.
This hypothesis has been verified by PerfMon perfcounter System.ContextSwitches.

Alhougt counterintuitive, AutoResetEvent , ManualResetEvent or even SpinLocking produced better behavior and with those the issue no longer reproduce.

Customer Impact
In case of XStore it was about 7 minutes in build time.

Regression?
Yes, introduced in VS 17.4.

Testing
Manual validation by @rokonec and automated tests. Using local repro to verify changes has fixed it.

Risk
Low

Note
It effect only VS MSBuild.exe. In dotnet build ManualResetEventSlim works better.

---------

Co-authored-by: Roman Konecny <rokonecn@microsoft.com>
Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants