File tree 3 files changed +22
-3
lines changed
src/main/java/com/google/devtools/build/lib/runtime
3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -745,6 +745,9 @@ private BlazeCommandResult execExclusively(
745
745
return result ;
746
746
} finally {
747
747
try {
748
+ // Profiler might still be running when an exception is thrown before BuildCompleteEvent is
749
+ // emitted or BlazeModule#completeCommand() is called. So we still need to try to stop the
750
+ // profiler here.
748
751
Profiler .instance ().stop ();
749
752
if (profilerStartedEvent .getProfile () instanceof LocalInstrumentationOutput profile ) {
750
753
profile .makeConvenienceLink ();
Original file line number Diff line number Diff line change @@ -765,6 +765,15 @@ public BlazeCommandResult afterCommand(
765
765
}
766
766
env .getBlazeWorkspace ().clearEventBus ();
767
767
768
+ // Some module's commandComplete() relies on the stoppage of profiler. And it is impossible the
769
+ // profiler is needed after all `BlazeModule.afterCommand`s are executed.
770
+ // See b/331203854#comment124 for more details.
771
+ try {
772
+ Profiler .instance ().stop ();
773
+ } catch (IOException e ) {
774
+ env .getReporter ().handle (Event .error ("Error while writing profile file: " + e .getMessage ()));
775
+ }
776
+
768
777
for (BlazeModule module : blazeModules ) {
769
778
try (SilentCloseable closeable = Profiler .instance ().profile (module + ".commandComplete" )) {
770
779
module .commandComplete ();
Original file line number Diff line number Diff line change @@ -192,9 +192,16 @@ public void buildComplete(BuildCompleteEvent event) {
192
192
}
193
193
}
194
194
if (profileEvent != null && profileEvent .getProfile () != null ) {
195
- // This leads to missing the afterCommand profiles of the other modules in the profile.
196
- // Since the BEP currently shuts down at the BuildCompleteEvent, we cannot just move posting
197
- // the BuildToolLogs to afterCommand of this module.
195
+ // The profiler has to be stopped before `BuildEventServiceModule#afterCommand` is called,
196
+ // especially when it is a bep artifact. An unstopped bep artifact could lead to a deadlock
197
+ // in `BuildEventServiceModule#afterCommand`.
198
+ //
199
+ // We choose to stop profiler here instead of in `BuildSummaryStatsModule#afterCommand` so
200
+ // that no ordering between GoogleBuildSummaryStatsModule and BuildEventServiceModule's
201
+ // `afterCommand`s needs to be assumed. See b/253394502.
202
+ //
203
+ // Stopping the profiler here leads to missing the afterCommand profiles of the other
204
+ // modules in the profile, which is a compromise we are willing to make.
198
205
try {
199
206
Profiler .instance ().stop ();
200
207
profileEvent .getProfile ().publish (event .getResult ().getBuildToolLogCollection ());
You can’t perform that action at this time.
0 commit comments