@@ -3110,48 +3110,51 @@ private void ShutdownLoggingService(ILoggingService? loggingService)
31103110 /// </summary>
31113111 private void Dispose ( bool disposing )
31123112 {
3113- if ( ! _disposed )
3113+ if ( disposing && ! _disposed )
31143114 {
3115- if ( disposing )
3115+ lock ( _syncLock )
31163116 {
3117- lock ( _syncLock )
3117+ if ( _disposed )
31183118 {
3119- // We should always have finished cleaning up before calling Dispose.
3120- RequireState ( BuildManagerState . Idle , "ShouldNotDisposeWhenBuildManagerActive" ) ;
3119+ // Multiple caller raced for enter into the lock
3120+ return ;
3121+ }
31213122
3122- _componentFactories ? . ShutdownComponents ( ) ;
3123+ // We should always have finished cleaning up before calling Dispose.
3124+ RequireState ( BuildManagerState . Idle , "ShouldNotDisposeWhenBuildManagerActive" ) ;
31233125
3124- if ( _workQueue != null )
3125- {
3126- _workQueue . Complete ( ) ;
3127- _workQueue = null ;
3128- }
3126+ _componentFactories ? . ShutdownComponents ( ) ;
31293127
3130- if ( _executionCancellationTokenSource != null )
3131- {
3132- _executionCancellationTokenSource . Cancel ( ) ;
3133- _executionCancellationTokenSource = null ;
3134- }
3128+ if ( _workQueue != null )
3129+ {
3130+ _workQueue . Complete ( ) ;
3131+ _workQueue = null ;
3132+ }
31353133
3136- if ( _noActiveSubmissionsEvent != null )
3137- {
3138- _noActiveSubmissionsEvent . Dispose ( ) ;
3139- _noActiveSubmissionsEvent = null ;
3140- }
3134+ if ( _executionCancellationTokenSource != null )
3135+ {
3136+ _executionCancellationTokenSource . Cancel ( ) ;
3137+ _executionCancellationTokenSource = null ;
3138+ }
31413139
3142- if ( _noNodesActiveEvent != null )
3143- {
3144- _noNodesActiveEvent . Dispose ( ) ;
3145- _noNodesActiveEvent = null ;
3146- }
3140+ if ( _noActiveSubmissionsEvent != null )
3141+ {
3142+ _noActiveSubmissionsEvent . Dispose ( ) ;
3143+ _noActiveSubmissionsEvent = null ;
3144+ }
31473145
3148- if ( ReferenceEquals ( this , s_singletonInstance ) )
3149- {
3150- s_singletonInstance = null ;
3151- }
3146+ if ( _noNodesActiveEvent != null )
3147+ {
3148+ _noNodesActiveEvent . Dispose ( ) ;
3149+ _noNodesActiveEvent = null ;
3150+ }
31523151
3153- _disposed = true ;
3152+ if ( ReferenceEquals ( this , s_singletonInstance ) )
3153+ {
3154+ s_singletonInstance = null ;
31543155 }
3156+
3157+ _disposed = true ;
31553158 }
31563159 }
31573160 }
0 commit comments