Inheritance: Microsoft.Azure.Amqp.ResourcesGeneric
Exemple #1
0
        public static Exception AssertAndFailFastService(string description)
        {
            Fx.Assert(description);
            string failFastMessage = CommonResources.GetString(CommonResources.FailFastMessage, description);

            // The catch is here to force the finally to run, as finallys don't run until the stack walk gets to a catch.
            // The catch makes sure that the finally will run before the stack-walk leaves the frame, but the code inside is impossible to reach.
            try
            {
                try
                {
                    ////MessagingClientEtwProvider.Provider.EventWriteFailFastOccurred(description);
                    Fx.Exception.TraceFailFast(failFastMessage);

                    // Mark that a FailFast is in progress, so that we can take ourselves out of the NLB if for
                    // any reason we can't kill ourselves quickly.  Wait 15 seconds so this state gets picked up for sure.
                    Fx.FailFastInProgress = true;
#if !WINDOWS_UWP
                    Thread.Sleep(TimeSpan.FromSeconds(15));
#endif
                }
                finally
                {
                    // ########################## NOTE ###########################
                    // Environment.FailFast does not collect crash dumps when used in Azure services.
                    // Environment.FailFast(failFastMessage);

#if !WINDOWS_UWP
                    // ################## WORKAROUND #############################
                    // Workaround for the issue above. Throwing an unhandled exception on a separate thread to trigger process crash and crash dump collection
                    // Throwing FatalException since our service does not morph/eat up fatal exceptions
                    // We should find the tracking bug in Azure for this issue, and remove the workaround when fixed by Azure
                    Thread failFastWorkaroundThread = new Thread(delegate()
                    {
                        throw new FatalException(failFastMessage);
                    });

                    failFastWorkaroundThread.Start();
                    failFastWorkaroundThread.Join();
#endif
                }
            }
            catch
            {
                throw;
            }

            return(null); // we'll never get here since we've just fail-fasted
        }
Exemple #2
0
        ////public static DiagnosticTrace Trace
        ////{
        ////    get
        ////    {
        ////        if (diagnosticTrace == null)
        ////        {
        ////            diagnosticTrace = InitializeTracing();
        ////        }

        ////        return diagnosticTrace;
        ////    }
        ////}

        public static byte[] AllocateByteArray(int size)
        {
#if !NETSTANDARD
            try
            {
#endif
            // Safe to catch OOM from this as long as the ONLY thing it does is a simple allocation of a primitive type (no method calls).
            return(new byte[size]);

#if !NETSTANDARD
        }
        catch (OutOfMemoryException exception)
        {
            // Convert OOM into an exception that can be safely handled by higher layers.
            throw Fx.Exception.AsError(new InsufficientMemoryException(CommonResources.GetString(CommonResources.BufferAllocationFailed, size), exception));
        }
#endif
        }
Exemple #3
0
        public void ExtractFrameBuffers(ByteBuffer buffer, SerializedWorker <ByteBuffer> bufferHandler)
        {
            if (this.currentFrameBuffer != null)
            {
                int sizeToWrite = Math.Min(this.currentFrameBuffer.Size, buffer.Length);

                AmqpBitConverter.WriteBytes(this.currentFrameBuffer, buffer.Buffer, buffer.Offset, sizeToWrite);
                buffer.Complete(sizeToWrite);

                if (this.currentFrameBuffer.Size == 0)
                {
                    ByteBuffer frameBuffer = this.currentFrameBuffer;
                    this.currentFrameBuffer = null;
                    bufferHandler.DoWork(frameBuffer);
                }
            }

            while (buffer.Length >= AmqpCodec.MinimumFrameDecodeSize)
            {
                int frameSize = AmqpCodec.GetFrameSize(buffer);
                if (frameSize < AmqpCodec.MinimumFrameDecodeSize || frameSize > this.maxFrameSize)
                {
                    throw new AmqpException(AmqpErrorCode.FramingError, CommonResources.GetString(CommonResources.InvalidFrameSize, frameSize, this.maxFrameSize));
                }

                int sizeToWrite = Math.Min(frameSize, buffer.Length);
                this.currentFrameBuffer = new ByteBuffer(frameSize, false);
                AmqpBitConverter.WriteBytes(this.currentFrameBuffer, buffer.Buffer, buffer.Offset, sizeToWrite);
                buffer.Complete(sizeToWrite);

                if (frameSize == sizeToWrite)
                {
                    ByteBuffer frameBuffer = this.currentFrameBuffer;
                    this.currentFrameBuffer = null;
                    bufferHandler.DoWork(frameBuffer);
                }
                else
                {
                    break;
                }
            }
        }
Exemple #4
0
 public AssertionFailedException(string description)
     : base(CommonResources.GetString(CommonResources.ShipAssertExceptionMessage, description))
 {
 }
Exemple #5
0
 protected static void ThrowInvalidAsyncResult(IAsyncResult result)
 {
     throw new InvalidOperationException(CommonResources.GetString(CommonResources.InvalidAsyncResultImplementation, result.GetType()));
 }
Exemple #6
0
            bool HandleReadComplete(TransportAsyncCallbackArgs args)
            {
                bool      completed = true;
                Exception exception = null;

                if (args.Exception != null)
                {
                    exception = args.Exception;
                }
                else if (args.BytesTransfered == 0)
                {
                    exception = new ObjectDisposedException(this.transport.ToString());
                }
                else if (args.BytesTransfered == args.Count)
                {
                    args.ByteBuffer?.Append(args.BytesTransfered);
                }
                else
                {
                    completed = false;
                    if (args.ByteBuffer == null)
                    {
                        args.SetBuffer(args.Buffer, args.Offset + args.BytesTransfered, args.Count - args.BytesTransfered);
                    }
                    else
                    {
                        args.ByteBuffer.Append(args.BytesTransfered);
                        args.SetReadBuffer(args.ByteBuffer);
                    }
                }

                if (completed)
                {
                    if (exception != null || object.ReferenceEquals(args.CompletedCallback, onFrameComplete))
                    {
                        ByteBuffer buffer = args.ByteBuffer;
                        try
                        {
                            if (exception == null)
                            {
                                this.parent.OnReceiveBuffer(buffer);
                            }
                            else
                            {
                                this.parent.OnIoFault(exception);
                            }
                        }
                        finally
                        {
                            buffer?.Dispose();
                        }
                    }
                    else
                    {
                        // read size completed ok
                        uint size = AmqpBitConverter.ReadUInt(this.sizeBuffer, 0, this.sizeBuffer.Length);
                        if (size > this.maxFrameSize)
                        {
                            completed = true;
                            exception = new AmqpException(AmqpErrorCode.FramingError, CommonResources.GetString(CommonResources.InvalidFrameSize, size, this.maxFrameSize));
                            this.parent.OnIoFault(exception);
                        }
                        else
                        {
                            ByteBuffer buffer = this.parent.CreateBuffer((int)size);
                            args.SetReadBuffer(buffer);
                            args.CompletedCallback = onFrameComplete;
                            completed = false;
                        }
                    }
                }

                return(completed);
            }
Exemple #7
0
 public ArgumentException ArgumentNullOrWhiteSpace(string paramName)
 {
     return(this.Argument(paramName, CommonResources.GetString(CommonResources.ArgumentNullOrWhiteSpace, paramName)));
 }