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

Server: Flush console output periodically #10231

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

rainersigwald
Copy link
Member

@rainersigwald rainersigwald commented Jun 12, 2024

This was the intention of the prior call, but _syncWriter.Flush() is
a noop because it's a wrapper around a TextWriter; instead we need to
flush the RedirectConsoleWriter itself, an operation which sends the
accumulated text to the client.

delayed output

@rainersigwald
Copy link
Member Author

@YuliiaKovalova I was trying to make a nice video of the before/after where this was working/not, but my most recent 8.0.3xx MSBuild didn't reproduce it--I think this regressed from #9983, somehow.

@YuliiaKovalova
Copy link
Member

@YuliiaKovalova I was trying to make a nice video of the before/after where this was working/not, but my most recent 8.0.3xx MSBuild didn't reproduce it--I think this regressed from #9983, somehow.

could you please check if reverting this change addresses it?
https://github.com/dotnet/msbuild/pull/9983/files/6ef1733094989a1b8d56bc5d2998061681cf12fb#diff-fc28ca0d80e868e8557a28620998ecee6d7e1def91d231109d4211dd3e4b2ba7

@rainersigwald
Copy link
Member Author

Yup, reverting just that file (and suppressing the warning) fixes the problem. Though I don't see how!

@rainersigwald
Copy link
Member Author

Ah, I see what happened. Before your change, TimerCallback called _syncWriter.Flush() which was a synchronized wrapper over RedirectConsoleWriter.Flush() so it did actually call the "send bits over the pipe" code, and in a thread-safe way since the call would be synchronized.

The current version of this PR fixes it but breaks the thread safety. I think I'll manage the locking manually without Syncronized().

@rainersigwald rainersigwald marked this pull request as ready for review June 14, 2024 16:59
@YuliiaKovalova
Copy link
Member

It looks like you address this ticket here:
#10013

Copy link
Member

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

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

Looks OK.

I'd just probably prefer if the resulting string handling callback is not part of the synchronization here. It doesn't already concern the writer, but rather the external processing of the data (sending them down the pipe)

src/Build/BackEnd/Node/OutOfProcServerNode.cs Show resolved Hide resolved
Initially, this delegated thread safety to a `SyncTextWriter`, but the
object graph was hard to understand, so it was replaced with a has-a
`SyncTextWriter` relationship, but this lost the timer-based call to
`Flush()` to send the output to the client.

The docs on `MethodImplOptions.Synchronized` also advise that it can be
risky due to locking on the object itself, so manage the syncronization
with an explicit lock object over the underlying `StringWriter` instead.
@rainersigwald rainersigwald merged commit 5b5222d into dotnet:main Jun 17, 2024
10 checks passed
@rainersigwald rainersigwald deleted the flush-server-console branch June 17, 2024 18:39
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