Ejemplo n.º 1
0
        private void HandleUnhandledFailure(LoggingContext loggingContext, Exception exception)
        {
            if (Interlocked.CompareExchange(ref m_handlingUnhandledFailureInProgress, 1, comparand: 0) != 0)
            {
                Thread.Sleep(TimeSpan.FromSeconds(3));

                ExceptionUtilities.FailFast("Second-chance exception handler has not completed in the allowed time.", new InvalidOperationException());
                return;
            }

            try
            {
                GeneratorExitCode  effectiveExitCode = GeneratorExitCode.InternalError;
                ExceptionRootCause rootCause         = exception is NullReferenceException
                    ? ExceptionRootCause.FailFast
                    : ExceptionUtilities.AnalyzeExceptionRootCause(exception);

                switch (rootCause)
                {
                case ExceptionRootCause.OutOfDiskSpace:
                case ExceptionRootCause.DataErrorDriveFailure:
                case ExceptionRootCause.DeviceAccessError:
                    effectiveExitCode = GeneratorExitCode.InfrastructureError;
                    break;

                case ExceptionRootCause.MissingRuntimeDependency:
                    effectiveExitCode = GeneratorExitCode.MissingRuntimeDependency;
                    break;
                }

                string failureMessage = exception.ToStringDemystified();

                if (effectiveExitCode == GeneratorExitCode.InfrastructureError)
                {
                    Logger.Log.UnhandledInfrastructureError(loggingContext, failureMessage);
                }
                else
                {
                    Logger.Log.UnhandledFailure(loggingContext, failureMessage);
                }

                if (rootCause == ExceptionRootCause.FailFast)
                {
                    ExceptionUtilities.FailFast("Exception is configured to fail fast", exception);
                }

                Environment.Exit((int)effectiveExitCode);
            }
            catch (Exception e)
            {
                PrintErrorToConsole("Unhandled exception in exception handler");
                PrintErrorToConsole(e.ToStringDemystified());
            }
            finally
            {
                Environment.Exit((int)GeneratorExitCode.InternalError);
            }
        }
Ejemplo n.º 2
0
        public void HandleError(object sender, Exception exception)
        {
            // Work around bug that is fixed in https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform/pullrequest/209513
            if (exception is NullReferenceException && exception.StackTrace.Contains("SpanTrackingWpfToolTipPresenter"))
            {
                return;
            }

            ExceptionUtilities.FailFast(exception);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Notifies the environment about a fatal exception and terminates the process.
        /// </summary>
        /// <param name="exception">An exception that represents the error that caused the termination.
        /// This is typically the exception in a catch block.</param>
        /// <param name="message">A message that explains why the process was terminated,
        /// or null if no explanation is provided.</param>
        public static void OnFatalException(Exception exception, string message = null)
        {
            Contract.RequiresNotNull(exception);

            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }

            // Note that we don't use Environment.FailFast. It isn't trustworthy; instead we go straight to the kernel.
            ExceptionUtilities.FailFast(message, exception);
        }
Ejemplo n.º 4
0
        private unsafe void CompletionWorkerThreadProc()
        {
            {
                int count;
                do
                {
                    count = Volatile.Read(ref m_completionPortRefCount);
                    if (count < 1)
                    {
                        // Manager disposed before this thread started.
                        return;
                    }
                }while (Interlocked.CompareExchange(ref m_completionPortRefCount, count + 1, comparand: count) != count);
            }

            try
            {
                while (true)
                {
                    FileSystemWin.IOCompletionPortDequeueResult result = FileSystemWin.GetQueuedCompletionStatus(m_completionPort);

                    Contract.Assume(
                        result.Status != FileSystemWin.IOCompletionPortDequeueStatus.CompletionPortClosed,
                        "We terminate all workers before closing the port (otherwise we risk a handle-recycle race).");

                    Contract.Assert(result.Status == FileSystemWin.IOCompletionPortDequeueStatus.Succeeded);

                    if (result.DequeuedOverlapped == null)
                    {
                        // Completion port is being closed; this is a poison message.
                        Contract.Assume(result.CompletionKey == s_queueCloseCompletionKey);
                        break;
                    }

                    // The OVERLAPPED* attached to each packet is unique to each I/O request. It should be one
                    // that we allocated earlier with AllocateOverlapped. We took care to place a request identifier
                    // immediately after the OVERLAPPED, so we can find the completion target.
                    Overlapped *deqeuedOverlapped = result.DequeuedOverlapped;
                    var         taggedOverlapped  = (TaggedOverlapped *)deqeuedOverlapped;

                    ReleaseOvelappedAndQueueCompletionNotification(taggedOverlapped, result.CompletedIO);
                }

                DecrementCompletionPortRefCount();
            }
            catch (Exception ex)
            {
                ExceptionUtilities.FailFast("Catastrophic failure in I/O completion worker", ex);
                throw;
            }
        }
Ejemplo n.º 5
0
        public void Dispose()
        {
            // Swap the available mask from all available to none available.
            // If this fails, there was a double-dispose or an overlapped is in use (so un-pinning would be scary).
            bool swapSucceeded = Interlocked.CompareExchange(ref m_availableEntryMask, 0L, comparand: ~0L) == ~0L;

            if (!swapSucceeded)
            {
                ExceptionUtilities.FailFast(
                    "OverlappedPoolNode was double-disposed or is still in use (outstanding I/O)",
                    new InvalidOperationException());
            }

            if (m_entriesPinningHandle.IsAllocated)
            {
                m_entriesPinningHandle.Free();
            }
        }
Ejemplo n.º 6
0
 public void HandleError(object sender, Exception exception)
 {
     ExceptionUtilities.FailFast(exception);
 }