Skip to content

Commit

Permalink
[dotnet] Fix hang after packing .NET NuGets. Fixes #13355. (#15407)
Browse files Browse the repository at this point in the history
This has been bothering me for a while... the symptom is that the build just
hangs at the end. Curiously it's never happend on the bots, only locally.

1. It only happens when using parallel make. When using parallel make, make is
   in a jobserver mode, where sub-makes are controlled using a pair of file
   descriptors inherited by the sub-makes. A consequence of this algorithm is
   that the controlling make process will wait until all inherited file
   descriptors have been closed before it will realize that all its sub-makes
   have finished.
2. 'dotnet pack' will build the corresponding project, and that might start a
   background compiler server.
3. This background compiler server does not seem to close any file descriptors
   it inherits.
4. The background compiler server does not necessarily exit by the time `make`
   is done.
5. The result is that `make` things there are still sub-makes doing stuff,
   because there are inherited file descriptors still open.
6. Killing the compiler server (in another terminal for instance) will make
   make realize it's done (and the hang is resolved).

So I'm applying the last point: shutting down the compiler server after
packing all the .NET NuGets.

Fixes #13355.
  • Loading branch information
rolfbjarne authored Jul 8, 2022
1 parent 279054a commit 1ecd843
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dotnet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,19 @@ clean-local::
$(DOTNET_DESTDIR)/Microsoft.iOS.Windows.Sdk/tools/msbuild/iOS/Xamarin.PreBuilt.iOS.app.zip: .stamp-install-workloads
$(Q) $(MAKE) -C $(TOP)/msbuild/Xamarin.HotRestart.PreBuilt all
$(Q) touch $@

# We need to shut down the builder server, because:
# We're using parallel make, and parallel make will start a jobserver, managed by file descriptors, where these file descriptors must be closed in all subprocesses for make to realize it's done.
# 'dotnet pack' might have started a build server
# The build server does not close any file descriptors it may have inherited when daemonizing itself.
# Thus the build server (which will still be alive after we're done building here) might have a file descriptor open which make is waiting for.
# The proper fix is to fix the build server to close its file descriptors.
# The intermediate working is to shut down the build server instead. An alternative solution would be to pass /p:UseSharedCompilation=false to 'dotnet pack' to disable the usage of the build server.
#
# The 'shutdown-build-server' is executed in a sub-make (and not as a dependency to the all-hook target),
# to make sure it's executed after everything else is built in this file.
all-hook::
$(Q) $(MAKE) shutdown-build-server

shutdown-build-server:
$(Q) $(DOTNET) build-server shutdown

1 comment on commit 1ecd843

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.